Removing Item from array with Underscore.js

后端 未结 3 400
不思量自难忘°
不思量自难忘° 2021-01-01 10:17

I have an array like this :

var array = [1,20,50,60,78,90];
var id = 50;

How can i remove the id from the array and return a new array tha

3条回答
  •  长情又很酷
    2021-01-01 10:34

    You can use splice, though it is not underscore's API:

    arrayObject.splice(index,howmany,item1,.....,itemX)
    

    In your example:

    var index = _.indexOf(array, id);
    array.splice(index, 1);
    

提交回复
热议问题