how to use the zipobjectdeep function from lodash in javascript

To use the zipObjectDeep function from Lodash in JavaScript, you need to first install and import the Lodash library. Once you have done that, you can use the zipObjectDeep function to create a new object composed from arrays of property names and values.

Here's an example code snippet that demonstrates how to use the zipObjectDeep function with Lodash:

index.tsx
const _ = require('lodash');

const propNames = ['a.b[0].c', 'a.b[1].c'];
const values = [1, 2];

const obj = _.zipObjectDeep(propNames, values);

console.log(obj);
// Output: { a: { b: [{ c: 1 }, { c: 2 }] } } 
212 chars
10 lines

In the above example, we define an array of property names and an array of values, and then call the zipObjectDeep function with those two arrays as arguments to create a new object with nested properties.

The resulting object has the property names and values "zipped" together, creating a nested object with the values in the correct places.

gistlibby LogSnag