Seeking advice on looping through an array of objects to achieve a specific result.
Here is the initial array:
var testArray = [{'name':'name1', 'xaxis':'xaxis1', 'yaxis':'yaxis1'},
{'name':'name2', 'xaxis':'xaxis2', 'yaxis':'yaxis2'}];
The length of the array may vary, but the keys remain consistent.
The desired result should be:
var resultArray = [
trace1 = {title: 'name1', x: 'xaxis1', y: 'yaxis1'},
trace2 = {title: 'name2', x: 'xaxis2', y: 'yaxis2'},
];
Started by creating variable names for JSON objects like this:
for (var i = 0; i < testArray.length; ++i) {
resultArray[i] = 'trace' + i;
}
Struggling with how to proceed in generating the JSON objects. Any advice would be appreciated.