Skip to main content

Built and signed on GitHub Actions

A modern JavaScript utility library that's 2-3 times faster and up to 97% smaller—a major upgrade to lodash.

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
2 weeks ago (1.31.0)
function property
property(path: PropertyKey | readonly PropertyKey[]): (object: unknown) => any

Creates a function that returns the value at a given path of an object.

Examples

Example 1

const getObjectValue = property('a.b.c'); const result = getObjectValue({ a: { b: { c: 3 } } }); console.log(result); // => 3

Example 2

const getObjectValue = property(['a', 'b', 'c']); const result = getObjectValue({ a: { b: { c: 3 } } }); console.log(result); // => 3

Parameters

path: PropertyKey | readonly PropertyKey[]
  • The path of the property to get.

Return Type

(object: unknown) => any
  • Returns a new function that takes an object and returns the value at the specified path.

Add Package

deno add jsr:@es-toolkit/es-toolkit

Import symbol

import { property } from "@es-toolkit/es-toolkit/compat";

---- OR ----

Import directly with a jsr specifier

import { property } from "jsr:@es-toolkit/es-toolkit/compat";

Add Package

npx jsr add @es-toolkit/es-toolkit

Import symbol

import { property } from "@es-toolkit/es-toolkit/compat";

Add Package

yarn dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { property } from "@es-toolkit/es-toolkit/compat";

Add Package

pnpm dlx jsr add @es-toolkit/es-toolkit

Import symbol

import { property } from "@es-toolkit/es-toolkit/compat";

Add Package

bunx jsr add @es-toolkit/es-toolkit

Import symbol

import { property } from "@es-toolkit/es-toolkit/compat";