Skip to main content
variable toPairs
import { toPairs } from "https://deno.land/x/30_seconds_of_typescript@v1.0.1/util.ts";

Creates an array of key-value pair arrays from an object or other iterable (object, array, string, set etc.).

Check if Symbol.iterator is defined and, if so, use Array.prototype.entries() to get an iterator for the given iterable, Array.from() to convert the result to an array of key-value pair arrays. If Symbol.iterator is not defined for obj, use Object.entries() instead.

const isArrayLike = (obj: any): obj is Array => { return ( obj[Symbol.iterator] instanceof Function && obj.entries instanceof Function ); };

type

(obj: any) => unknown