jhohlfeld jhohlfeld - 2 years ago 122
Javascript Question

In lodash, what is the opposite of `pairs()`?

I cant't see it in the docs - http://lodash.com/docs - please help me:

What is the opposite of

? There must be one - I just cant' see where!

The goal is to produce key/value pairs from an array of the form
[['key1':'value1'], ['key2':'value2'], ...]

Not that I really need it a lib for that: I just like to re-use things..

Answer Source

I think you're looking for _.object/_.zipObject.


"use strict";

var obj, pairs, objResult;

obj = {
    key1: "value1",
    key2: "value2"

pairs = _.pairs(obj);
objResult = _.object(pairs);

// The original object.
// The object as an array of arrays.
// The array of arrays converted back to the original object.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download