Array
Array
The JavaScript Array object is a global that is used in theconstruction of arrays;
which are high-livel, list-like objects.
Create an Array
var fruits = ['Apple', 'Banana'];
Access(index into)an Array item
var first = fruits[0];
var last = fruits[fruits.length - 1];
Loop over an Array
fruits.forEach(function(item, index, array) {
console.log(item, index);
});
//Apple 0 Banana 1
Add to the end of an Array
var newLength = fruits.push('Orange');
// ['Apple', 'Banana', 'Orange']
Remove from the end of an Array
var last = fruits.pop(); // remove Orange(form the end)
Remove from the front of an Array
var first = fruits.shift(); // remove Apple from the front
Add to the front of an Array
var newLength = fruits.unshift('Strawberry') // add to the front
Find the index of an item in the Array
fruits.push('Mango'); // ['Strawberry', 'Banana', 'Mango']
var pos = fruits.indexOf('Banana'); // [1]
The JavaScript Array object is a global that is used in theconstruction of arrays;
which are high-livel, list-like objects.
Create an Array
var fruits = ['Apple', 'Banana'];
Access(index into)an Array item
var first = fruits[0];
var last = fruits[fruits.length - 1];
Loop over an Array
fruits.forEach(function(item, index, array) {
console.log(item, index);
});
//Apple 0 Banana 1
Add to the end of an Array
var newLength = fruits.push('Orange');
// ['Apple', 'Banana', 'Orange']
Remove from the end of an Array
var last = fruits.pop(); // remove Orange(form the end)
Remove from the front of an Array
var first = fruits.shift(); // remove Apple from the front
Add to the front of an Array
var newLength = fruits.unshift('Strawberry') // add to the front
Find the index of an item in the Array
fruits.push('Mango'); // ['Strawberry', 'Banana', 'Mango']
var pos = fruits.indexOf('Banana'); // [1]
下一篇:西厢记.游园
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:★☆☆☆☆
文章难度:☆☆☆☆☆
文章质量:★☆☆☆☆
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!
本文打字排名TOP20
登录后可见
用户更多文章推荐
- The Butterfly Effect2018-03-27
- 7 Ways to Turn Yourself into a2017-03-23