Chrome Extension

Lodash - Convert paired Array to key value paired object

You can convert Array pairs to Object key-value pairs using Lodash. The method fromPairs is used to make Object from Array Pairs.
const subject = [
    ['name', 'Math'], 
    ['score', 90],
    ['dept', 'Mathematics']
];
const subject_obj = _.fromPairs(subject);
// => { "name": "Math", "score": 90, "dept": "Mathematics"}
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

_.fromPairs(pairs) Lodash

_.fromPairs(pairs_array);

pairs_array: [Required] You can pass the paired array into this parameter. In the code snippet subject is our paired array.

Example Demo

Search Index Data (The code snippet can also be found with below search text)

_.fromPairs lodash
Was this helpful?
0 Comments
Join Devsheet Ask a Question