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

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.

主站蜘蛛池模板: 涿鹿县| 龙口市| 星座| 东兴市| 大关县| 孝感市| 长葛市| 高雄县| 灵武市| 南安市| 隆昌县| 新民市| 太原市| 克拉玛依市| 宜良县| 赤壁市| 离岛区| 河南省| 称多县| 五峰| 咸宁市| 会泽县| 合江县| 游戏| 重庆市| 衡东县| 高邑县| 遂川县| 星子县| 翼城县| 桦川县| 平和县| 扎鲁特旗| 大连市| 黑河市| 二手房| 宜兰县| 晋宁县| 左贡县| 丹凤县| 佛坪县|