Friday, October 24, 2025
HomeLanguagesJavascriptLodash _.at() Method

Lodash _.at() Method

Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, lang, function, objects, numbers etc.

The _.at() method creates an array of values corresponding to paths of object.

Syntax:

_.at(object, [paths])

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

  • object: It holds the object to iterate over.
  • [paths]: It holds the property paths to pick.

Return Value: This method returns the picked values.

Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.




// Requiring the lodash library 
const _ = require("lodash"); 
       
// Original array 
var object = { 'p': [{ 'q': { 'r': 7 } }, 9] };
  
// Using the _.at() method
let at_elem = _.at(object, ['p[0].q.r', 'p[1]']);
  
// Printing the output 
console.log(at_elem);


Output:

[ 7, 9 ]

Example 2:




// Requiring the lodash library 
const _ = require("lodash"); 
       
// Original array 
var object = { 'oppo': [{ 'vivo': { 'moto': 1900 } }, 2400] 
  
};
  
// Using the _._.at() method
let at_elem = _.at(object, ['oppo[0].vivo.moto', 'oppo[1]']);
  
// Printing the output 
console.log(at_elem);


Output:

[ 1900, 2400 ]

Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.

Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, neveropen Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS