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

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.

主站蜘蛛池模板: 郧西县| 通城县| 郑州市| 威信县| 精河县| 五台县| 长宁区| 磴口县| 克东县| 梅河口市| 天台县| 射阳县| 肇源县| 平湖市| 阿鲁科尔沁旗| 漯河市| 大厂| 黄浦区| 米易县| 洪洞县| 荔浦县| 尚志市| 博乐市| 海安县| 盐津县| 泽库县| 分宜县| 赞皇县| 海阳市| 鹤庆县| 新宾| 沧源| 星子县| 漳平市| 文昌市| 松潘县| 峨山| 舟山市| 常熟市| 哈尔滨市| 玉山县|