Need help with organizing my code
let newArr = [];
$.post( "/reports/search", { query:'*'},function(data) {
for(let i=0; i<data.length; i++) {
newArr[i].value = data[i].name;
newArr[i].data = data[i].id;
}
},'json');
I am trying to create a JSON array variable with a specific structure
newArr = [ {"value":"aaa", data:"1"},
{"value":"bbb", data:"2"},
{"value":"ccc", data:"3"}
]
Any suggestions on how to achieve this in JavaScript?