I am having confusion on how to do it with $.map function instead of regular $.each.
I have json data like this.
var arr = {
"x1" :[11,22,33],
"y1":[44,55,66],
"y2":[77,88,99]
};
And result should be array = [[x1,y1,y2], ...]
var result = [[11,44,77],[22,55,88],[33,66,99]];
And I want function to be dynamic , it should not depend on arr.x1 etc .For example If i give it array like
var arr2 = {
"aaa" :[11,22,33],
"sss":[44,55,66],
"dd":[77,88,99],
"dddd":[77,88,99],
};
It should add up all array like above dynamically as it have now 4 sub arrays so result should be three sub-arrays of four elements each.
I should be able to do it with $.each etc but purpose is to learn $.map.
UPDATE: My guess is pure $.map solution will be something like nested maps:
_elements = $.map(_elements, function(e) {
return [$.map(e,function(v) {
return v;
})];
});
arrarray isn't actually an array; it's an object. As such, the order of your result can't be guaranteed.arr2should produce 4 sub-arrays. Don't you mean it should produce three sub-arrays of four elements each?$.mapis a one-to-one transformation engine.arrandarr2, because these names will confuse you into thinking the objects are arrays when they are not.