js knowledge point--continuously updated
1. How to convert a collection to an array
Where A is the object that needs to be operated
- Array.from(A)
- [].slice.applay(A)
- [].map.call(A, o => o)
- […A]
var str = "hello";
console.log("1.使用Array.from:", Array.from(str));
console.log("2.使用[].slice.apply:", [].slice.apply(str));
console.log("3.使用[].map.call:", [].map.call(str, o => o));
console.log("4.使用[...]:", [...str]);
display effect: