1. 程式人生 > >偽數組如何轉成數組

偽數組如何轉成數組

type 數組 pro 方法 使用 proto cal length 大學

1.使用Array.prototype.slice.call();

Array.prototype.slice.call({
0:"yeluosen",
1:12,
2:true,
length:3
});
//["yeluosen", 12, true]

2.使用[].slice.call()

[].slice.call({
0:"yeluosen",
1:12,
2:true,
length:3
});
//["yeluosen", 12, true]

3.使用ES6中Array.from方法

Array.from({
0:"葉落森",
1:18,
2:2014,
3:"北京郵電大學",
length:4
});
//["葉落森", 18, 2014, "北京郵電大學"]

偽數組如何轉成數組