1.将字符串,对象等作为伪数组转换成数组: Array.from()
将伪数组转变成数组,就是只要有length的长度就可以转成数组 --ES6
let str = '12345' console.log(Array.from(str)) let obj={0:'a',1:'b',length:2} console.log(Array.from(obj)) //这样将字符串每个变为索引元素
2.将一组值转换成数组,类似声明为数组 --es6
Array.of()
let str='11' console.log(Array.of(str)) //['11'] console.log(new Array('11')) //['11'] //但是参数问题会引起重载 加字符串是数组,不加是是长度 console.log(new Array(2)) //enmpty x2 console.log(Array.of(2)) //['2']
let str='11' console.log(Array.of(str)) //['11'] console.log(new Array('11')) //['11'] //但是参数问题会引起重载 加字符串是数组,不加是是长度 console.log(new Array(2)) //enmpty x2 console.log(Array.of(2)) //['2']