Get object from array of objects in Javascript -
i have array:
var arrayexample = [ {productid: 1, quantity: 2, name: example, description: example}, {productid: 1, quantity: 2, name: example, description: example}, {productid: 1, quantity: 2, name: example, description: example}, {productid: 1, quantity: 2, name: example, description: example}];
my question
how items of array taking in every object productid , quantity? having array contains objects 2 values? number of objects of array variable
result:
var arrayexamplenew = [ {productid: 1, quantity: 2}, {productid: 1, quantity: 2}, {productid: 1, quantity: 2}, {productid: 1, quantity: 2}];
sorry english
you map
var arrayexample = [{ productid: 1, quantity: 2, name: 'example', description: 'example' }, { productid: 1, quantity: 2, name: 'example', description: 'example' }, { productid: 1, quantity: 2, name: 'example', description: 'example' }, { productid: 1, quantity: 2, name: 'example', description: 'example' }]; var arr = arrayexample.map(function(item) { return {productid : item.productid, quantity : item.quantity } }); console.log(arr)
Comments
Post a Comment