Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

const people = {
 base: {
   name: 'zhang san',
   age: 25,
   clothes: [
     { name: 'jack', color: 'red' },
     { name: 'suit', color: 'black' }
   ]
 },
 children: [
   { name: 'son1', gender: 'male', age: 3 },
   { name: 'girl1', gender: 'female', age: 1 }
 ]
}
function getObjectByPath (obj, path) {
 // return result
}
console.log(getObjectByPath(people, 'base.age')) // 25
console.log(getObjectByPath(people, 'base.clothes[0].name')) // jack
console.log(getObjectByPath(people, 'children[0].name')) // son1

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
4.1k views
Welcome To Ask or Share your Answers For Others

1 Answer

Lodash get方法


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...