GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

No menu could be recovered. Follow the blue links in the page.

This view

  • Original page
  • New address

GeezerVison is showing zh.javascript.info — 数组操作。

  • 教程
  • JavaScript 编程语言
  • 数据类型
  • 数组
回到课程

数组操作。

重要程度: 5

我们试试下面的 5 个数组操作。

  1. 创建一个数组 styles,里面存储有 “Jazz” 和 “Blues”。
  2. 将 “Rock-n-Roll” 从数组末端添加进去。
  3. 用 “Classics” 替换掉数组最中间的元素。查找数组最中间的元素的代码应该适用于任何奇数长度的数组。
  4. 去掉数组的第一个值并显示它。
  5. 在数组前面添加 Rap 和 Reggae。

过程中的数组:

Jazz, Blues
Jazz, Blues, Rock-n-Roll
Jazz, Classics, Rock-n-Roll
Classics, Rock-n-Roll
Rap, Reggae, Classics, Rock-n-Roll
let styles = ["Jazz", "Blues"];
styles.push("Rock-n-Roll");
styles[Math.floor((styles.length - 1) / 2)] = "Classics";
alert( styles.shift() );
styles.unshift("Rap", "Reggae");
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.