_.slice(arr,start,end)

node v8.11.1
version: 1.0.0
endpointsharetweet
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