Search code snippets, questions, articles...

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


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?
Programming Feeds
Learn something new everyday on Devsheet