Javascript – 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:


Best Solution

dependentProperties.push({name: depName, value: depValue});