Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var array = [{'id':1, 'Color':'blue'},
- {'id':2, 'Color':'orange'},
- {'id':3, 'Color':'green'},
- {'id':4, 'Color':'blue'} ];
- var myFilter = array.filter(function (item) {
- return item.Color === 'blue';
- });
- var result = array.filter(function(item) {
- return item.Color === 'blue';
- }).map(function(item) {
- return item.id;
- });
- console.log(result)
- # [1, 4]
- var result = _.chain(array)
- .filter(function(item) {
- return item.Color === 'blue';
- })
- .pluck("id")
- .value();
- console.log(result);
- # [1, 4]
- var result = _.chain(array)
- .where({Color: 'blue'})
- .pluck("id")
- .value();
- console.log(result)
- # [1, 4]
- console.log(_.pluck(_.where(array, {Color: 'blue'}), "id"));
- # [1, 4]
- var result = [];
- for (var i = 0; i < array.length; i += 1) {
- if (array[i].Color === "blue") {
- result.push(array[i].id);
- }
- }
- console.log(result);
- # [1, 4]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement