首页 > 编程语言 >手写算法-lodash get

手写算法-lodash get

时间:2022-12-27 12:22:19浏览次数:53  
标签:paths return lodash get defaultValue result 手写

lodash get

function get(source, path, defaultValue = undefined){
  const paths = path.replace(/\[(\d+)\]/g, '$1').split('.')
  let result = source;
  for(let p of paths){
    result = Object(result)[p]
    if(result === undefined){
     return defaultValue
    }
  }
 return result
}

标签:paths,return,lodash,get,defaultValue,result,手写
From: https://www.cnblogs.com/yiyunh/p/17007795.html

相关文章