Skip to content

prop() function

객체에서 속성의 값을 가져오거나, 객체에 속성이 존재하지 않으면 undefined를 반환합니다.

Signature:

typescript
declare function prop<K extends Key, T>(key: K, obj: T): Prop<T, K>;

Example

ts
// get the `name` property from an object
const person = { name: "John", age: 30 };
const name = prop("name", person); // "John"

// with pipe
pipe(person, prop("name"));

// get the `address` property from an object that may be null or undefined
const maybePerson = null;
const address = prop("address", maybePerson); // undefined

Open Source Code

Released under the Apache-2.0 License.