Skip to main content
Using Deno in production at your company? Earn free Deno merch.
Give us feedback
Module

x/yano3nora_tsutils/main.ts>objectByKeys

TypeScript Utilities as a npm dual package by Deno.
Go to Latest
variable objectByKeys
import { objectByKeys } from "https://deno.land/x/yano3nora_tsutils@v0.17.0/main.ts";

Examples

objectByKeys([1, 2, 3]) //=> { '1': undefined, '2': undefined, '3': undefined }

objectByKeys([1, 2, 3], 'initial') // => { '1': 'initial', '2': 'initial', '3': 'initial' }

objectByKeys([1, 2, 3], key => key * 10) // => { '1': 10, '2': 20, '3': 30 }

type

<T extends string | number | symbol, U = undefined>(keys: T[], initial?: U | ((key: T) => U)) => Record<T, U>