Thursday 15 January 2015

json - How do you extract/where the javascript list with an array property -


I have to remove the javascript object list using underscore.js, where

the original JSON list < {"Id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}] < / Code>

and filter to arrays:

['2', '3', '5']

The resulting list will be:

  [{"id": 2}, {"id": 3}, {"id": 5}]   

How can I get it using the underscores method and I can think of all those where

How about a _.filter?

  var arr = ['2', '3', '5']; Var input = [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6 }]; Var filtered = _.filter (input, function (obje) {return_.indexOf (arr, obj.id.toString ())> 1 /}>   

< / Div>

No comments:

Post a Comment