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

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -