For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/zipObject.md.

zipObject es-toolkit

Creates a single object from a keys array and a values array.

const object = zipObject(keys, values);

Usage

zipObject(keys, values)

Use zipObject when you want to combine two arrays into a single object. It returns a new object where elements from the first array become keys and elements from the second array become values.

import { zipObject } from 'es-toolkit/array';

// Create an object from keys and values.
zipObject(['a', 'b', 'c'], [1, 2, 3]);
// Returns: { a: 1, b: 2, c: 3 }

// If there are more keys, undefined becomes the value.
zipObject(['a', 'b', 'c', 'd'], [1, 2, 3]);
// Returns: { a: 1, b: 2, c: 3, d: undefined }

If the values array is longer, excess values are ignored.

import { zipObject } from 'es-toolkit/array';

zipObject(['a', 'b'], [1, 2, 3, 4]);
// Returns: { a: 1, b: 2 }

Parameters

keysreadonly P[]required

The array that will become the object's keys.

valuesreadonly V[]required

The array of values corresponding to each key.

Returns

Returns a new object with keys and values combined.

Record<P, V>
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.