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?
Similar Posts
- Convert object {key: value} to Array [[key, value]] Javascript
- Filter an Array using object key value in Javascript
- Sort array of objects by key value in Javascript
- Remove a key or property from Object in Javascript
- Remove an object from array by value in Javascript
- Replace array values with another value Lodash
- Lodash - Get index of first occurence of an array value