1亮靴、將偽(類)數(shù)組轉(zhuǎn)換成數(shù)組
<body>
<script>
window.onload = function(){
let oLi = document.querySelectorAll('li');
// oLi.push('eee');
// console.log(oLi); //oLi.push is not a function
let aLi = [...oLi]; //準換成數(shù)組
aLi.push('cyril');
console.log(aLi); // [li,li,li,li,'cyril']
}
</script>
<ul>
<li>aaa</li>
<li>bbb</li>
<li>ccc</li>
<li>ddd</li>
</ul>
</body>
把類數(shù)組轉(zhuǎn)換成數(shù)組還有一種寫法:let aLi = Array.from(oLi); 也就是用這段代碼替換掉上段代碼中的 let aLi = [...oLi];
Array.of() :類似于...擴展運算符偏序,將一組值轉(zhuǎn)換成數(shù)組:
let arr = Array.of('apple','banana','orange');
Array.of = function(...args){
return args;
}
console.log(arr); //["apple","banana","orange"]
2、arr.find() 查找第一個符合條件的數(shù)組成員,沒有找到返回undefined
let arr = [40,90,120,115,113];
let newArr = arr.find((val,index,arr) => {
return val > 100;
});
console.log(newArr);
3礁凡、arr.findIndex() 查找第一個符合條件的數(shù)組成員的索引,沒有找到返回undefined
let arr = [40,90,120,115,113];
let newArr = arr.findIndex((val,index,arr) => {
return val > 100;
});
console.log(newArr);
4、arr.includes() ES6新增的包含某個子元素
let arr = [40,90,120,115,113];
let newArr = arr.findIndex((val,index,arr) => {
return val > 100;
});
console.log(newArr);
GitHub個人主頁 :https://github.com/Cyrildog
諸多問題沒有答案欲账,就是最后的答案;某份感情沒有結(jié)果芭概,可能就是最好的結(jié)果赛不。
[圖片上傳失敗...(image-7dafe-1529574868469)]