Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

What is the opposite of _.pairs()? 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..

like image 551
jhohlfeld Avatar asked Dec 21 '13 06:12

jhohlfeld


People also ask

How do I compare two arrays of objects in Lodash?

isEqual() Method. The Lodash _. isEqual() Method performs a deep comparison between two values to determine if they are equivalent. This method supports comparing arrays, array buffers, boolean, date objects, maps, numbers, objects, regex, sets, strings, symbols, and typed arrays.

What is _ get?

Overview. The _. get() method in Lodash retrieves the object's value at a specific path. If the value is not present at the object's specific path, it will be resolved as undefined . This method will return the default value if specified in such a case.

How do I merge two arrays in Lodash?

If both arrays are in the correct order; where each item corresponds to its associated member identifier then you can simply use. var merge = _. merge(arr1, arr2);

What is Lodash Noop?

The Lodash _. noop() method is used to return “undefined” irrespective of the arguments passed to it. Syntax: _.noop() Parameters: This method can take optional parameters of any type. Returns: This method returns undefined.


1 Answers

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

http://lodash.com/docs#zipObject

"use strict";  var obj, pairs, objResult;  obj = {     key1: "value1",     key2: "value2" };  pairs = _.pairs(obj); objResult = _.object(pairs);  // The original object. console.log(obj); // The object as an array of arrays. console.log(pairs); // The array of arrays converted back to the original object. console.log(objResult); 

http://jsfiddle.net/HmDk6/

like image 54
Peter Majeed Avatar answered Sep 22 '22 14:09

Peter Majeed