DEV Community

Annaavh
Annaavh

Posted on

Why array.splice() method isn't working right? Which array method can help to solve the problem?

function foo(arr,num){
return arr.map((item,index,arr) => {
return arr.splice(index,num)
})
}
console.log(foo([1, 2, 3, 4, 5], 2))
//The expected output should be [[1,2],[3,4],[5]]
//In this case output is [[1,2],[4,5]]

Top comments (0)