Har*_*ess 0 arrays jquery associative-array object multidimensional-array
尝试创建以下内容:
array('12345'=>'A01','A02','
A03''22222'=>'B01',
'33333'=>'C01','C02')
所以基本上每个键都是从另一个数组动态生成的.假设某个事件被触发后变量数字为'12345'.
我们有一个名为location的数组,例如这个数组('A01','A02','A03')
那么在主阵列上,它将映射两个数字和位置.这是每次有事件时我需要保存的数组.
在下一个事件执行中,我们将在数字变量(例如'22222')上获得新值,然后新的数组位置将覆盖另一个('B01'),例如,依此类推.
请记住,键将始终是动态的,值可以是1到50,例如我们不知道.我知道这更像是Jquery上的Object Literals.thx提前.
这是一段代码,需要能够获得密钥和值
$.each(dragarray, function(index, value) {
dragid_loc['value'] = [];
// do loop to add each element of other array
$.each(draglocation, function(index2, value2) {
dragid_loc.value.push(value2);
});
});
console.log(dragid_loc);
Run Code Online (Sandbox Code Playgroud)
这条线似乎导致问题我不会将另一个数组draglocation的值推入每个.需要获得关键和价值.
dragid_loc.value.push(value2);
Run Code Online (Sandbox Code Playgroud)
根据评论,我认为你需要的是:
obj["newProp"] = []; // A new property is added to the object with key newProp and an empty array as valueobj.newProp.push(newElement); // A new element is added to the array in newProp of object