一些 js 知识点

js知识点 -- 持续更新

1、将集合转化为数组的方法

其中A为需要进行操作的对象

  • 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]);

显示效果:
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Matcha_ice_cream/article/details/123941231