我有一个包含键和值的数组,我想将哪些元素推入 2 个不同的数组(键入一个,值入另一个)
这是我使用的代码:
// the array i want to split
var defaultc = {
'a':'r019',
'b':'r027',
'c':'r027',
'd':'r027',
'e':'r047'
};
// the array i want to add to
var step_layer = []; // keys to this
var step_colour = {}; // values to this
$('#reset').click(function() {
$.each(defaultc, function(layer, colour) {
// both these functions are working properly
apply_changes(layer, colour);
sumary(layer, colour);
});
// this part is not
for (var layer in defaultc) {
if (!defaultc.hasOwnProperty(layer)) {
step_layer.push(layer);
step_colour[layer].push(colour);
}}
return false;
});