![]() |
VOOZH | about |
Lodash _.zipObject() method is used to combine two arrays into an object one array as keys and the other as values.
_.zipObject([props=[]], [values=[]]);Example 1: In this example, we are getting an object by passing two arrays in the _.zipObject() method.
Output:
{ a: 1, b: 2, c: 3 }Example 2: In this example, we are getting an object by passing two arrays in the _.zipObject() method.
Output:
{ name: 'lodash', ';language': 'JavaScript', used: 'nodejs' }Example 3: In this example, If you pass an extra key and no values for it, it will put undefined value associated with that key.
Output:
{ a: 1, b: 2, c: 3, d: undefined }Example 4: In this example, If you pass an extra value and no key for it, it will ignore that value.
Output:
{ a: 1, b: 2, c: 3 }Note: This will not work in normal JavaScript because it requires the library lodash to be installed.