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

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.

主站蜘蛛池模板: 惠东县| 诏安县| 夏邑县| 会昌县| 昌吉市| 涡阳县| 广河县| 张北县| 郸城县| 博白县| 宜州市| 花莲县| 墨竹工卡县| 浦县| 洞头县| 新野县| 铜梁县| 安顺市| 邓州市| 遂川县| 德惠市| 五大连池市| 淄博市| 舒城县| 舒城县| 黄骅市| 深州市| 新蔡县| 兴化市| 嘉黎县| 安陆市| 弥勒县| 凌海市| 弥勒县| 泗洪县| 宜君县| 厦门市| 轮台县| 马鞍山市| 红河县| 乐清市|