`_.get` function on object using JavaScript Library underscore.js ( #shorts )
Hi Friends,
`_.get` function on object using JavaScript Library underscore.js
`_.get` is a utility function in Underscore.js library is commonly used to retrieve the value of a nested property within an object, even if some intermediate properties do not exist without facing errors due to missing or undefined intermediate properties.
In below example, we have an object person with nested properties representing a person's details. We use _.get to retrieve the value of the city property within the address object. The result is "New York".
Note: _.get helps you handle situations where intermediate properties may be missing or undefined, preventing errors and allowing you to provide fallback values if needed.
// syntax
_.get(object, path, [defaultValue])
// example
var person = { name: "Annie", address: {
city: "New York",
street: { number: 123, name: "Main Street" }
}
};
var cityName = _.get(person, "address.city");
console.log(cityName);
// "New York"
#javascript #under #score #underscore #underscorejs #get #underscoreget #getfunction #unique #object #array #string #nodejs #javascriptinterview #method #js #jquery #function #shorts #viral #popular #latest #new #coders #development #code #dev #interview #php #trend #trending #answer #laravel #youtube #instagram #socialmedia #education #edit #how #india #knowledge #quiz #reels #short #subscribe #share #update #video #web #webdeveloper #website #webdesign #ytshorts #youtuber #princecheema_official @princecheema_official
-
0:10
Pawanvir Singh Cheema
1 year ago`_.reject` function on array using JavaScript Library underscore.js ( #shorts )
3 -
0:10
Pawanvir Singh Cheema
1 year ago`_.clone` function on object or array using JavaScript Library underscore.js ( #shorts )
11 -
6:41
NorbertBM
1 year ago $0.01 earnedAll JavaScript Array Methods for Beginners
66 -
11:18
LearnCode.academy
1 year agoJavascript Selectors - Javascript Tutorial for Beginners With Examples
3 -
7:26
FreelanceMogul
8 months agoString methods in Javascript | Javascript String Methods
5 -
12:03
Tech With Tim
4 years agoJavaScript for Beginners #6 - Introduction to Functions
2 -
8:54
T & M
5 months agoLearn JSON Files in Javascript
10 -
3:46
EasilyCoded
1 year agoLearn How to Easily Extract Values from Objects Properties in JavaScript
7 -
2:58:06
Tech With Tim
3 years ago $0.02 earnedAn Introduction to JavaScript - Course for Beginners
87 -
3:49
richbray
1 year agoTips for naming variables and functions in programming | Javascript
2