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

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.

主站蜘蛛池模板: 乐业县| 红河县| 巴林右旗| 台北市| 衡山县| 双流县| 会东县| 长葛市| 利川市| 明水县| 黔东| 乌审旗| 迁安市| 山阴县| 甘洛县| 宿州市| 渭南市| 黄龙县| 新昌县| 安吉县| 天津市| 乐至县| 东乡县| 乌拉特后旗| 江阴市| 建水县| 呼图壁县| 崇信县| 古田县| 仁布县| 五大连池市| 儋州市| 台南市| 壶关县| 灌云县| 台北县| 遵义县| 丰顺县| 安远县| 望都县| 双城市|