Skip to content

Pops

Remove the given keys from the given object.

๐ŸŽฌ Usage

<script>
    import {pops} from "@sveu/shared/dicts"

    const obj = {"Mila": "Kunis", "Emma": "Watson", "Scarlett": "Johansson"}

    pops(obj, ["Mila", "Emma"])

    obj // {"Scarlett": "Johansson"}
</script>

๐Ÿ‘ฉโ€๐Ÿ’ปAPI

๐Ÿ‘ป Arguments

Name Description Type Required
obj object to pop from Record<string | number | symbol, any> yes
keys keys to pop string[] yes

๐Ÿงช Playground

Source Code ๐Ÿ‘€

Source Code
/**
 * Remove the given keys from the given object.
 *
 * @param obj - The object to remove keys from.
 *
 * @param keys - The keys to remove.
 *
 */
export function pops<T, K extends keyof T>(obj: T, keys: K[]) {
    for (const key of keys) {
        delete obj[key]
    }
}

Last update: 2023-02-14