
Camila Waz
发布于
2020-04-29 15:16:44
es6 数组的entries(),keys()和values()实例方法
Array.keys(): 返回键名的遍历器。
Array.values(): 返回键值的遍历器。
Array.entries(): 返回所有成员键值对遍历器。
Array.values(): 返回键值的遍历器。
Array.entries(): 返回所有成员键值对遍历器。
const array=['good', '1230','.com']1、Array.keys()
for (let index of array.keys()) { console.log(index); } // 0 // 1 // 22、Array.values()
for (let elem of array.values()) { console.log(elem); } // 'good' // '1230' // '.com'3、Array.entries()
for (let [index, elem] of array.entries()) { console.log(index, elem); } // 0 "good" // 1 "1230" // 2 ".com"
最后生成于 2020-12-28 15:07:50