Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

add value to each object in array javascript

var labels = ["DESKTOP", "MOBILE", "TABLET"];
var chartData = ["100", "10", "15"];
var myData = [];

labels.forEach(function(e, i) {
  myData.push({
    label: e,
    data: chartData[i]
  })
})

document.write(JSON.stringify(myData));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #add #object #array #javascript
ADD COMMENT
Topic
Name
9+4 =