Blogger Information
Blog 25
fans 0
comment 0
visits 9457
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
前端开发20221102
P粉114035831
Original
367 people have browsed it

数组的分类

单个数组 多维数组 对象数组 类数组 函数数组

// 数组
const arr = [‘电脑’, 5000, true]

// 逐个索引
console.log(array:, arr[0], arr[1], arr[2])
// 判断: 不用typeof, 用 Array.isArray(arr)
console.log(Array.isArray(arr))

console.log(‘—————————‘)

// 多维数组
const arr1 = [
[1, 水果, 10],
[2, 疏菜, 20],
[3, 蛋糕, 30],
]

arr1.forEach(function (item,key,arr1) { console.log(item, key, arr1)})
// 箭头函数
arr1.forEach(item => console.log(item))

console.log(‘—————————‘)

// 对象数组
const fruits = [
{id:1, name:水果, price:10},
{id:2, name:疏菜, price:20},
{id:3, name:蛋糕, price:30},
]

fruits.forEach (item => console.log(item))

console.log(‘—————————‘)

// 类数组
const likeArr = {
0:admin,
1:admin@qq.com,
3:157482,
length:3,
}
// 类数组转为真正的数组
console.log(Array.from(likeArr))

Array.from(likeArr).forEach(item => console.log(item))

console.log(‘—————————‘)

// 函数数组
const events = [function(){return 捉住把手},function(){return旋钮把手},function(){return打开门},]
// 箭头函数简化
const events = [() =>捉住把手, () =>旋钮把手, () =>打开门,]
// 函数数组表达
events.forEach(ev => console.log(ev()))

console.log(‘—————————‘)

Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post