deetu
deetu

Reputation: 79

Array order change

I have a mongo query that returns an array in the format below, how do I change it

[[12, 1359410400000], [18, 1359410400000]]

to look like this

[[ 1359410400000, 12], [ 1359410400000,18]]

Upvotes: 1

Views: 114

Answers (2)

mVChr
mVChr

Reputation: 50185

newArr = [];
oldArr.forEach(function(v, i){ newArr[i] = [v[1], v[0]]; });

Upvotes: 1

the system
the system

Reputation: 9336

mongoArray.forEach(function(arr) {
    arr.reverse();
});

Or more concise like this:

mongoArray.forEach(Function.call.bind([].reverse));

Upvotes: 1

Related Questions