Array.prototype.hyslice = function(start, end) {
var arr = this
start = start || 0
end = end || arr.length
var newArray = []
for (var i = start; i < end; i++) {
newArray.push(arr[i])
}
return newArray
}
var newArray = Array.prototype.hyslice.call(["aaaa", "bbb", "cccc"], 1, 3)//从第一个位置截到第三个位置(不包含第三个位置)
console.log(newArray)
// var newArray = Array.prototype.hyslice.call(arguments)
// console.log(newArray)
var names = ["aaa", "bbb", "ccc", "ddd"]
names.slice(1, 3)
js数组中的slice实现
最新推荐文章于 2024-05-23 14:57:36 发布