007 数组扩展_新增方法
1、Array.from()
Array.from方法用于将数组转为真正的数组
温馨提示:常见的类数组有三类:①arguments②元素集合③类似数组的对象
①arguments
function add(){
let collect =Array.from(arguments);
collect.push(40);
console.log(collect);
}
add(10,20,30)
②元素集合
let divs=document.querySelectorAll('div');
console.log(Array.from(divs));
③类似数组的对象
let arrayLike={
'0':'a',
'1':'b',
'2':'c',
length:3
};
let arr=Array.from(arrayLike);
console.log(arr);
2、Array.of()
Array.of方法用于将一组值,转换为数组
Array.of(3,11,8)//[3,11,8]



浙公网安备 33010602011771号