我添加了一个小问题,你可以解决问题http://jsfiddle.net/ro59fxow/
var myFolders = ['abc','bcd','cda']; //these values are dynamic
var a1 = myFolders[0];
var folder = {
a1:['11'], //this is giving a1 ,i want here abc
folder1: ['sss','www'],
folder2 : ['uvw','xyz']
}
myFolders.push(folder);
console.warn(myFolders);
提前致谢
答案 0 :(得分:0)
将第二个数组合并到第一个数组中使用以下代码。
Array.prototype.push.apply(myFolders,folder.folder2);
输出:[“abc”,“bcd”,“cda”,“uvw”,“xyz”]
答案 1 :(得分:0)
您可以使用以下代码,我应该理解您的问题。
var myFolders = ['abc','bcd','cda']; //these values are dynamic
var a1 = myFolders[0];
console.log(a1);
var folder = {};
folder[a1] = ['111']; //use this syntax to evaluate the variable as a key value.
myFolders.push(folder);
console.warn(myFolders);