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

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.

主站蜘蛛池模板: 虞城县| 阜阳市| 中山市| 英吉沙县| 汾西县| 西青区| 江阴市| 天门市| 讷河市| 沙坪坝区| 阳谷县| 达拉特旗| 衡东县| 玛纳斯县| 昆山市| 娄烦县| 蓬莱市| 宁陕县| 蓬莱市| 班玛县| 张家港市| 凤庆县| 宁波市| 安化县| 奇台县| 纳雍县| 津市市| 右玉县| 介休市| 新和县| 淮安市| 濉溪县| 北票市| 宁蒗| 修文县| 和政县| 时尚| 民权县| 论坛| 德庆县| 庆云县|