官术网_书友最值得收藏!

Understanding arrays

Arrays work the same way in JavaScript as they do in pretty much any other language. They are zero indexed, and you can declare a variable as an empty array or a pre-populated array. You can manipulate the items in an array, and arrays are not fixed in length:

var favFoods = ['pizza', 'cheeseburgers', 'french fries']; 
var stuff = [];        // empty array 
var moreStuff = new Array();       // empty array 
var firstFood = favFoods[0];    // => pizza

// array functions: favFoods.push('salad'); // add new item

// => ['pizza', 'cheeseburgers', 'french fries', 'salad'] favFoods.pop(); // remove the last item // => ['pizza', 'cheeseburgers', 'french fries'] var first = favFoods.shift(); // remove the first item // => first = 'pizza'; // => favFoods = ['cheeseburgers', 'french fries']

To be more precise, you can consider arrays as extended child classes of the base Object class with extra implementations of Array functions.

主站蜘蛛池模板: 安陆市| 农安县| 武乡县| 岳池县| 元氏县| 抚顺市| 邵武市| 汉寿县| 泾川县| 金川县| 雷山县| 乐昌市| 台前县| 东乌珠穆沁旗| 禄劝| 庆云县| 突泉县| 万盛区| 运城市| 白银市| 澳门| 鄯善县| 徐水县| 渭南市| 长治市| 齐河县| 肥乡县| 郴州市| 子长县| 马公市| 滨海县| 阿荣旗| 和平区| 昌黎县| 会理县| 卢湾区| 中方县| 兴宁市| 万全县| 兴和县| 大悟县|