user1934044 user1934044 - 3 months ago 22
Javascript Question

programatically create json array object in javascript

My code is

var arr=[];
$.post( "/reports/search", { query:'*'},function(data) {
for(var i=0;i<data.length;i++)


I want to create a json array variable and i want the resut like below

arr=[ {"value":"aaa",data:"1"},


How to do it in javascript


This will work in all modern browsers:

var arr ={return {value:, data:});

In ES6 (with deconstruction and renaming):

var arr ={name: value, id: data}) => ({ value, data }))