JSON数组:如何创建新的数组元素? [英] json array: How to create new array elements?
本文介绍了JSON数组:如何创建新的数组元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的目标是获得一个JSON数组像这样的:
变参= {[名称:'测试',值:1},{关键:测试2,值:2}]。
我怎样才能获得低于code建立像上述之一的阵列?
this.dependentProperties = []; //数组
功能addDependentProperty(depName,depValue){
dependentProperties.push(新阵列(depName,depValue));
}
通过使用push方法我最终不得不像这样的一个JSON对象:
的args:{[[测试1,1],[测试2,2]}
解决方案
dependentProperties.push({名depName,值:depValue});
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]]}
解决方案
dependentProperties.push({name: depName, value: depValue});
这篇关于JSON数组:如何创建新的数组元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文