ECMAScript 6 —— 知识点(六) 数组

var divs = document.querySelectorAll('div');
var arr = Array.from(divs);//将对象转为数组
arr.forEach(console.log);

var nums = Array.of(3,11,8);//[3,11,8]
[1,2,3,4,5].copyWithin(0,3);//[4, 5, 3, 4, 5]
[1,2,3,4,5].copyWithin(0,3,2)//[1, 2, 3, 4, 5]
[1, 2, 3, 4, 5].copyWithin(0,-2,-1);//[4,2,3,4,5]
[1,3,5,7,9].find(n => n > 3);//5
[1,2,3,4,5].findIndex(n=> n > 3);//3,返回索引
'Hello World'.split('').fill('6',1,4);//["H", "6", "6", "6", "o", " ", "W", "o", "r", "l", "d"] 从索引1到索引4之前填充7

for(let index of ['b','a'].keys()){
    console.log(index);
}

for(let elem of ['a','b'].values()){
    console.log(elem);
}

猜你喜欢

转载自blog.csdn.net/wuxinwudai/article/details/80828820