ut2
Version:
一个现代 JavaScript 实用工具库。[点击查看在线文档]。
22 lines (21 loc) • 680 B
TypeScript
import { Many, TPath } from './internals/types';
/**
* 获取对象路径的值。
*
* @alias module:Object.get
* @since 1.16.0
* @param {*} object 要查询的对象。
* @param {string | number | symbol | Array} path 属性路径字符串或数组。
* @param {*} [defaultValue] 替代返回 `undefined` 的默认值。
* @returns {*} 属性值。
* @example
* const obj = { a: [{ b: { c: 1 } }] };
*
* get(obj, 'a[0].b.c'); // 1
*
* get(obj, ['a', '0', 'b', 'c']); // 1
*
* get(obj, 'a.b.c', 'default'); // 'default'
*/
declare function get<TDefault = unknown>(object: any, key: Many<TPath>, defaultValue?: TDefault): TDefault | undefined;
export default get;