把arguments转换为数组

来源:互联网 发布:数据结构设计怎么写 编辑:程序博客网 时间:2024/06/05 13:30

笔试遇到的题目,记录一下

把arguments转换为数组的方法

console.log(arguments instanceof Array);//falsevar argsArray=Array.prototype.slice.call(arguments);console.log(argsArray instanceof  Array);//true
方法就是Array.prototype.slice.call(arguments);

同样也可以把getElementsByTagName的到的nodeList转换为数组

Array.prototype.slice.call(nodes);

0 0