<script>
//Array.from可把实现了迭代器接口的数据类型,转换成真正的对象
let arrayLike={
0:'小红',
1:'小张',
length:2
};
console.log(arrayLike);
//1.把类数组arrayLike转换为纯数组
let arrList=Array.from(arrayLike);
console.log(arrList);
//2.验证arrList为纯数组,使用数组专用.forEach(fn(val,key){})进行遍历
arrList.forEach(function(val,key){
console.log(key,val);
});
//3.实现了迭代器接口的数据:将字符串转化为纯数组
let strList=Array.from('xiaohong');
console.log(strList);
//4.验证strList为纯数组,使用数组专用.forEach(fn(val,key){})进行遍历
strList.forEach(function(val,key){
console.log(key,val);
});
//5.数组扩展运算符作用于字符串:将字符串转化为纯数组
let args=[...'hellow'];
console.log(args);
</script>