Skip to content
geeksforgeeks
  • Tutorials
    • Python
    • Java
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
    • Practice Coding Problems
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • TypeScript
  • Vue.js
  • D3.js
  • Collect.js
  • Underscore.js
  • Moment.js
  • Ember.js
  • Tensorflow.js
  • Fabric.js
  • JS Formatter
  • JavaScript
  • Web Technology
Open In App
Next Article:
Underscore _.get() Function
Next article icon

Underscore _.get() Function

Last Updated : 01 Feb, 2022
Comments
Improve
Suggest changes
Like Article
Like
Report

Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invokes, etc even without using any built-in objects.

The _.get() function is an inbuilt function in the Underscore.js library of JavaScript which is used to get the value at the path of object. If the resolved value is undefined, the defaultValue is returned in its place.

Syntax:

_.get(object, path, [defaultValue])

Parameters: This method accepts three parameters as mentioned above and described below:

  • object: This parameter holds the object to query.
  • path: This parameter holds the path of the property to get. The path will be array or string.
  • defaultValue: This parameter holds the value returned for undefined resolved values.
  • Return Value: This method returns the resolved value.

Example 1:

HTML
<!DOCTYPE html> <html> <head>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/underscore-umd-min.js">     </script> </head> <body>     <script>          // Given object         var object = { 'c': [{ 'python': { 'java': 3 } }] };                    // Use of _.get method          console.log(_.get(object, 'c'));      </script> </body> </html> 

Output:

[{ 'python': { 'java': 3 } }] 

Example 2:

HTML
<!DOCTYPE html> <html> <head>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/underscore-umd-min.js">     </script> </head> <body>     <script>                 // Given object         var object = { 'c': [{ 'python': { 'java': 3 } }] };                    // Use of _.get method          console.log(_.get(object, ['c', '0', 'python', 'java']));      </script> </body> </html> 

Output:

3

Example 3:

HTML
<!DOCTYPE html> <html> <head>     <script src= "https://cdn.jsdelivr.net/npm/[email protected]/underscore-umd-min.js">     </script> </head> <body>     <script>              // Given object         var object = { 'c': [{ 'python': { 'java': 3 } }] };                    // Use of _.get method          console.log(_.get(object, 'c.python.java', 'default'));      </script> </body> </html> 

Output:

default

Reference: https://underscorejs.org/#get


Next Article
Underscore _.get() Function

S

SHUBHAMSINGH10
Improve
Article Tags :
  • JavaScript
  • Web Technologies
  • JavaScript - Underscore.js
  • underscore

Similar Reads

    Underscore.js _.rest() Function
    The Underscore.js is a JavaScript library that provides a lot of useful functions like the map, filter, invoke etc even without using any built-in objects. The _.rest() is used to return the rest of the elements except the zeroth indexed element. Second parameter is used to start the search from the
    3 min read
    Underscore.js _.tap() Function
    Underscore.js is a JavaScript library that provides a lot of useful functions that help in the programming in a big way like the map, filter, invoke, etc even without using any built-in objects. The _.tap() function is an inbuilt function in Underscore.js library of JavaScript which is used to call
    2 min read
    Underscore.js _.range() Function
    _.range() function: It is used to print the list of elements from the start given as a parameter to the end also a parameter. The start and step parameters are optional. The default value of start is 0 and that of step is 1. In the list formed the start is inclusive and the stop is exclusive. The st
    3 min read
    Underscore.js _.result() Function
    Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc even without using any built-in objects. The _.result() function is an inbuilt function in Underscore.js library of JavaScript. Here, if the state
    2 min read
    Underscore.js _.reject Function
    The Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc even without using any built-in objects. The _.reject() function is used to give the answer which does not match with the given condition. It
    3 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences