javascript

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"}

_.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

Was this helpful?