Clone and edit this document
Runkit
Runkit
home page
user forum
new notebook
clone notebook
download notebook
support & documentation
log in
sign up
new notebook
help & feedback
clone this notebook
download this notebook
Sign In
Sign Up
_.slice(arr,start,end)
node v8.17.0
version:
1.0.0
endpoint
share
tweet
function slice(array,start,end){ let length = array == null ? 0 : array.length if(!length){ return [] } start = start == null ? 0 : start end = end === undefined ? length : end if(start < 0){ start = -start > length ? 0 : (length + start) } end = end > length ? length : end if(end < 0){ end += length } length = start > end ? 0 : ((end - start) >>> 0) start >>>= 0 let index = -1 const result = new Array(length); while(++index < length){ result[index] = array[index + start] } return result }
var arr = [1,2,3,4,5] console.log(slice(arr,1,3))
Loading…
no comments
sign in
to comment