0

I have following kind of data

    "val1": [0.31, 0.3069, 0.3038],
    "val2": ["2015-01-14", "2015-06-14", "2016-01-14"],
    "val3": [0.1, 0.11, 0.11]

I want to create different array which will be as follows

    [0.31, "2015-01-14", 0.1],
    [0.3069, "2015-06-14", 0.11],
    [0.3038, "2016-01-14", 0.11]

How can I create this kind of array using underscore.js ? Can anyone please tell me how to do this.

Thanks

1 Answer 1

1

You can use _.values and _.zip like this

var obj = {
    "val1": [0.31, 0.3069, 0.3038],
    "val2": ["2015-01-14", "2015-06-14", "2016-01-14"],
    "val3": [0.1, 0.11, 0.11]
};

console.log(_.zip.apply(_, _.values(obj)));

Output

[ [ 0.31, '2015-01-14', 0.1 ],
  [ 0.3069, '2015-06-14', 0.11 ],
  [ 0.3038, '2016-01-14', 0.11 ] ]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.