Array

贡献者:dudusky 类别:代码 时间:2017-03-13 09:16:28 收藏数:29 评分:0
返回上页 举报此文章
请选择举报理由:




收藏到我的文章 改错字
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]
声明:以上文章均为用户自行添加,仅供打字交流使用,不代表本站观点,本站不承担任何法律责任,特此声明!如果有侵犯到您的权利,请及时联系我们删除。
文章热度:
文章难度:
文章质量:
说明:系统根据文章的热度、难度、质量自动认证,已认证的文章将参与打字排名!

本文打字排名TOP20

登录后可见

用户更多文章推荐