user1934044 user1934044 - 1 year ago 85
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

Answer Source

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 }))
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download