<script>
var wrap= document.getElementsByClassName('wrap')[0];
var wrapChildren = wrap.getElementsByTagName('div');
console.log(wrapChildren); //HTMLCollection(4) [div, div, div, div]
/*
用原生js获取的元素级 elementcollection,nodeList
是一个类数组
*/

/*定义一个空数组,然后push*/
/*let arr = [];
for(let item of wrapChildren){
arr.push(item);
}
console.log(arr);
*/

/*Array.from 类数组-->数组*/
/*
var trueArray = Array.from(wrapChildren);
console.log(trueArray);
*/

/*...运算符*/
/*
var trueArray = [...wrapChildren];
console.log(trueArray);
*/

/*apply的第二个参数可以是数组,也可以是类数组*/
/*
var trueArray = [].concat.apply([],wrapChildren);
console.log(trueArray);
*/

var trueArray = Array.prototype.slice.call(wrapChildren);
console.log(trueArray);
</script>
posted on 2019-12-06 10:49  喜欢金龙最好不过  阅读(249)  评论(0编辑  收藏  举报