javascript - How do I convert an array of integers to an array of objects? -


i convert , array in format

var values = [1,2,3];  

to array in format

var data = [    {x: 0, value: 1},   {x: 1, value: 2},   {x: 2, value: 3} ]; 

you use array.prototype.map method:

var data = values.map(function(el, i) {    return {      x: i,      value: el    } }); 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

how to prompt save As Box in Excel Interlop c# MVC 4 -

xslt 1.0 - How to access or retrieve mets content of an item from another item? -