S
S
Stepan Kormilin2015-11-16 15:49:21
JavaScript
Stepan Kormilin, 2015-11-16 15:49:21

Remove elements from an array in javascript?

Good afternoon!
There are two arrays. The first is [1,2,3] and the second is [{id:1},{id:2},{id:3},{id:4},{id:5}]. I need to get the third array [{id:4},{id:5}], that is, how to remove from the second array elements with id equal to the values ​​of the elements of the first array?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
Y
Yaroslav Lyzlov, 2015-11-16
@dixoNich

var f = [1,2,3]; var ff =  [{id:1},{id:2},{id:3},{id:4},{id:5}]

ff.filter(function (el) { return ~f.indexOf(el.id) })

S
Sergey, 2015-11-16
Protko @Fesor

Array.prototype.filter
Array.prototype.indexOf

V
Valery Serov, 2015-11-16
@DrBronson

var mass = [{id:1},{id:2},{id:3},{id:4},{id:5}].map(function(){
 //И ПАНЕСЛАСЬ
})

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question