source: node_modules/es-toolkit/dist/array/zipObject.d.mts

Last change on this file was a762898, checked in by istevanoska <ilinastevanoska@…>, 5 months ago

Added visualizations

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * Combines two arrays, one of property names and one of corresponding values, into a single object.
3 *
4 * This function takes two arrays: one containing property names and another containing corresponding values.
5 * It returns a new object where the property names from the first array are keys, and the corresponding elements
6 * from the second array are values. If the `keys` array is longer than the `values` array, the remaining keys will
7 * have `undefined` as their values.
8 *
9 * @template P - The type of elements in the array.
10 * @template V - The type of elements in the array.
11 * @param {P[]} keys - An array of property names.
12 * @param {V[]} values - An array of values corresponding to the property names.
13 * @returns {Record<P, V>} - A new object composed of the given property names and values.
14 *
15 * @example
16 * const keys = ['a', 'b', 'c'];
17 * const values = [1, 2, 3];
18 * const result = zipObject(keys, values);
19 * // result will be { a: 1, b: 2, c: 3 }
20 *
21 * const keys2 = ['a', 'b', 'c'];
22 * const values2 = [1, 2];
23 * const result2 = zipObject(keys2, values2);
24 * // result2 will be { a: 1, b: 2, c: undefined }
25 *
26 * const keys2 = ['a', 'b'];
27 * const values2 = [1, 2, 3];
28 * const result2 = zipObject(keys2, values2);
29 * // result2 will be { a: 1, b: 2 }
30 */
31declare function zipObject<P extends PropertyKey, V>(keys: readonly P[], values: readonly V[]): Record<P, V>;
32
33export { zipObject };
Note: See TracBrowser for help on using the repository browser.