How to filter objects from array javascript
var products = [{"_id":1,"name":"product1 ","description":"good product"},
{"_id":2,"name":"product2 ","description":"good product"},
{"_id":3,"name":"product3 ","description":"good product"},
{"_id":4,"name":"product4 ","description":"good product"},
{"_id":5,"name":"product5 ","description":"good product"}]
var newArray = products.filter(function (el) {
return el._id > 2;
});
-------Output------
[{"_id":3,"name":"product3 ","description":"good product"},
{"_id":4,"name":"product4 ","description":"good product"},
{"_id":5,"name":"product5 ","description":"good product"}]
Comments
Post a Comment