- Web Development with MongoDB and Node(Third Edition)
- Bruno Joseph D'mello Mithun Satheesh Jason Krol
- 151字
- 2021-07-08 10:32:44
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.
推薦閱讀
- 深入核心的敏捷開發(fā):ThoughtWorks五大關(guān)鍵實(shí)踐
- Google Apps Script for Beginners
- 自制編譯器
- Apache Hive Essentials
- Java游戲服務(wù)器架構(gòu)實(shí)戰(zhàn)
- Apache Spark Graph Processing
- Java Web從入門到精通(第3版)
- Unity 2018 Augmented Reality Projects
- MySQL程序員面試筆試寶典
- JavaScript機(jī)器人編程指南
- Managing Microsoft Hybrid Clouds
- 貫通Tomcat開發(fā)
- Java程序性能優(yōu)化實(shí)戰(zhàn)
- 現(xiàn)代JavaScript編程:經(jīng)典范例與實(shí)踐技巧
- 區(qū)塊鏈原理、設(shè)計(jì)與應(yīng)用