什么是伪数组(类数组)?
参考答案
有 length 和数字索引,但没有数组原型方法(map/forEach 等)的对象。
典型
arguments、NodeList、HTMLCollection、字符串、{0:'a',1:'b',length:2}
转真数组
Array.from(args);
[...args]; // 需可迭代
Array.prototype.slice.call(args);
判断:Array.isArray(x) === false 且 typeof x.length === 'number'。