jiaqingjiayi-xiaochengxu/甲情_甲意/node_modules/antd-mini/es/_util/get.js

11 lines
476 B
JavaScript
Raw Normal View History

2024-11-15 03:51:28 +00:00
export function get(obj, path, defaultValue) {
// If path is not an array, convert it to an array
if (!Array.isArray(path)) {
path = path.split('.').map(function (key) { return key.replace(/\[(\d+)]/g, '$1'); });
}
// Use reduce to traverse the path
var result = path.reduce(function (acc, key) { return (acc && acc[key] !== undefined ? acc[key] : undefined); }, obj);
return result === undefined ? defaultValue : result;
}
export default get;