Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

json array: How to create new array elements?

My aim is to get a json array like this one:

var args = [{ name: 'test', value: 1 }, { key: 'test2', value: 2}];

How can I get the below code to build up an array like the above one?

this.dependentProperties = []; //array
function addDependentProperty(depName, depValue) {    
    dependentProperties.push(new Array(depName, depValue));
} 

By using the push method I end up having a json notation like this one:

args:{[["test1",1],["test2",2]]}
like image 687
Andre Gallo Avatar asked Jul 01 '09 03:07

Andre Gallo


1 Answers

dependentProperties.push({name: depName, value: depValue});
like image 83
Luca Matteis Avatar answered Oct 03 '22 18:10

Luca Matteis