Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/ayonli_jsext/object/index.ts>partitionEntries

A JavaScript extension package for building strong and modern applications.
Latest
function partitionEntries
import { partitionEntries } from "https://deno.land/x/ayonli_jsext@v0.9.72/object/index.ts";

Returns a tuple of two records with the first one containing all entries of the given record that match the given predicate and the second one containing all that do not.

Examples

Example 1

import { partitionEntries } from "@ayonli/jsext/object";

const obj = { foo: "Hello", bar: "World" };
const [match, rest] = partitionEntries(obj, ([key]) => key === "foo");

console.log(match); // { foo: "Hello" }
console.log(rest); // { bar: "World" }

Parameters

record: Record<string, T>
predicate: (entry: [string, T]) => boolean

Returns

[Record<string, T>, Record<string, T>]