您当前的位置:首页 > 网站建设笔记 >

Array.prototype.slice.call()

0

Array.prototype.slice.call(arguments)能将具有length属性的对象转换成数组,除了IE下的节点集合(因为ie下的dom对象是以com对象的形式实现的,js对象与com对象不能进行转换)

<script type="text/javascript">
var a={length:2, 0:"first", 1:"second"};
console.log(Array.prototype.slice.call(a,0));//输出["first", "second"]

var a={length:2, 0:"first", 1:"second"};
console.log(Array.prototype.slice.call(a,1));//输出["second"]

var a={0:"first", 1:"second"};//去掉length属性, 返回一个空数组
console.log(Array.prototype.slice.call(a,0));//输出[]

function test(){
  console.log(Array.prototype.slice.call(arguments,0));//输出["a", "b", "c"]
  console.log(Array.prototype.slice.call(arguments,1));//输出["b", "c"]
}
test("a","b","c");

var a={0:"first", 1:"second"};
function test(){
  console.log(Array.prototype.slice.call(arguments,0));//输出[Object]
  console.log(Array.prototype.slice.call(arguments,1));//输出[]
}
test(a);
</script>

建站咨询

在线咨询真诚为您提供专业解答服务

咨询热线

137 1731 25507×24小时服务热线

微信交流

二维码终于等到你,还好我没放弃
返回顶部