Array.of
let array = Array.of(3,4,7,9,11);
console.log('array='+array);//array=[3,4,7,9,11]
let empty = Array.of();
console.log('empty='+empty);//empty=[]
Array.from
//将伪数组转化为数组
**html**
<html lang="en">
<head>
<meta charset="UTF-8">
<title>es6title>
head>
<body>
<p>p1p>
<p>p2p>
<p>p3p>
body>
html>
**es6**
let p = document.querySelectorAll('p');
let pArray = Array.from('p');//将集合转化为数组
pArray.forEach(function(item){
console.log(item.textContent);
/**
*p1
*p2
*p3
*/
})
console.log(Array.from([1,3,5],function(item){return item*2}))
//[2,6,10]
fill
console.log('fill-7',[1,'a',undefined].fill(7));
//fill-7 ⇒ [7,7,7]
console.log('fill,pos',['a','b','c'].fill(7,1,3));
//fill,pos ⇒ ['a',7,7]
keys
for(let index of ['1','c','ks'].keys()){
console.log('keys', index);
/**
* keys ⇒ 0
* keys ⇒ 1
* keys ⇒ 2
*/
}
values
for(let value of ['1','c','ks'].values()){
console.log('values', value);
/**
* values ⇒ 1
* values ⇒ c
* values ⇒ ks
*/
}
entries
for(let [index, value] of ['1','c','ks'].entries()){
console.log('entries', value);
/**
* entries ⇒ 0 1
* entries ⇒ 1 a
* entries ⇒ 2 ks
*/
}
copyWithin
console.log([1,2,3,4,5].copyWithin(0,3,4));
//[4,2,3,4,5]
find与findIndex
console.log([1,2,3,4,5,6].find(function(item){return item>3})):
//4
console.log([1,2,3,4,5,6].findIndex(function(item){return item>3})):
//3
includes
console.log('number',[1,2,NaN].includes(1));
//number ⇒ true
console.log('number',[1,2,NaN].includes(NaN));
//number ⇒ true