The Wayback Machine - https://web.archive.org/web/20240901104730/https://www.geeksforgeeks.org/lodash-_-at-method/
Open In App

Lodash _.at() Method

Last Updated : 09 Sep, 2020
Comments
Improve
Suggest changes
Like Article
Like
Save
Share
Report
News Follow

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.


Previous Article
Next Article

Similar Reads

Lodash _.method() Method
Lodash _.method() method creates a function that invokes the method at the path of a given object. Any additional arguments are provided to the invoked method. Syntax: _.method(path, args);Parameters: path: This is the path to invoke.args: These are the arguments to invoke the method with.Return Value: This method returns the new invoker function.
1 min read
Lodash _.flattenDeep() and _.flattenDepth() Method
Lodash _.flattenDeep() Method The _.flattenDeep() method is used to completely flatten nested arrays. It does this recursively. Syntax: _.flattenDeep( array ) Parameters: This method accepts single parameter as mentioned above and described below: array: This parameter holds the array that to be flatten. Return Value: This method returns the new fl
2 min read
Lodash _.stubFalse() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.stubFalse() method is used to always return a false value. The basic difference between using a normal false value and using the _.stubFalse() method is that lambda functions create a new different functi
1 min read
Lodash _.pullAllBy() Method
The _.pullAllBy() method is used to remove the values from the original array by iterating over each element in the array by using the Iteratee function. It is almost the same as _.pullAll() function. Syntax: _.pullAllBy(array, values, [iteratee=_.identity]) Parameters: This method accepts two parameters as mentioned above and described below: arra
2 min read
Lodash _.sortedLastIndexOf() Method
The _.sortedLastIndexOf method is used to return the highest index of the array where an element can be inserted and maintain its sorted order. Also this method is like _.lastIndexOf except that it performs a binary search on a sorted array.Syntax: _.sortedLastIndexOf(array, value) Parameters: This method accepts two parameters as mentioned above a
1 min read
Lodash _.isSymbol() Method
The _.isSymbol() method is used to find whether the given value is a symbol object or not. It returns True if the given value is a symbol object. Otherwise, it returns false. Syntax: _.isSymbol(value) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter holds the value to check. Return Val
1 min read
Lodash _.toArray() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.toArray() method is used to convert the given value to an array. Syntax: _.toArray( value ) Parameters: This method accepts a single parameter as mentioned above and described below: value: This parameter
1 min read
Lodash _.reduce() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc. The _.reduce() method reduces collection to value which is accumulated result of running each element in the collection through iteratee, where each successive invocation is supplied return value of
2 min read
Lodash _.splitAt() Method
The Lodash _.splitAt() method takes an array and a numeric index and returns a new array containing two embedded arrays made by splitting the original array at the provided numeric index. Syntax: _.splitAt(array, numeric_index) Parameters: This method takes two parameters as mentioned above and described below: array: The array to be split.numeric_
3 min read
Lodash _.stubString()Method
The Lodash _.stubString() method is used to create an empty string. Syntax: _.stubString() Parameters: This method does not accept any parameter. Return Value: This method returns an empty string. Example 1: C/C++ Code // Requiring the lodash library const _ = require("lodash"); // Use of _.stubString() method // to create an empty String
1 min read
Lodash _.curry2() Method
The Lodash _.curry2() method returns a curried version of the given function but will curry exactly two arguments, no more or less. Syntax: _.curry2( fun ) Parameters: This method takes a single parameter as listed above and discussed below. fun: This is the given function. Return Value: It returns a curried version of the function. Note: To execut
2 min read
Lodash _.flatMapDepth() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc. The _.flatMapDepth() method creates a flattened array of values by running each element in the given collection through the iteratee function. It recursively flattens the mapped results up to the giv
2 min read
Lodash _.conformTo() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, collection, strings, objects, numbers etc. The _.conformsTo() method checks if object conforms to source by invoking the predicate properties of source with the corresponding property values of object and this method is equivalent to _.confor
2 min read
Lodash _.cycle() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.cycle() method is then used to build a new array containing the given number of iterations of the given array, that are string end-to-end. Thus, the new array created contains the given array number of gi
2 min read
Lodash _.cat() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.cat() method is used to concatenate zero or more arguments into one array. It can be used to concatenate multiple types of arguments, Syntax: _.cat( arg1, arg2, ..., argn ) Parameters: args: This method a
2 min read
Lodash _.chunkAll() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.chunkAll() Method is used to break the given array in to small chunks of the given size. It is similar to the _.chunk() method except that this method will never drop short chunks from the end. Syntax: _.
2 min read
Lodash _.keepindexed() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.keepIndexed() method takes an array and a function as parameters and returns a new array filled with the non-null return results of the given function acted upon the elements of the given array. Syntax: _
2 min read
Lodash _.keep() Method
The Lodash _.keep() method takes an array and a function and hence returns an array generated which keeps only true values based on the conditions of the function. Syntax: _.keep( array, function ) Parameters: This method takes two parameters as mentioned above and described below: array: The given array from which keep array is created.function: T
2 min read
Lodash _.weave() Method
The Lodash _.weave() method takes two arrays and returns an array with both arrays woven together. Note: The array returned from _.weave() method will be woven till the shortest array, rest array values will be the same. Syntax: _.weave(array1, array2) Parameters: This method takes two parameters as mentioned above and described below: array1: The
2 min read
Lodash _.second() Method
The Lodash _.second() method takes an array and an index and hence returns an array generated by taking elements from the original array starting with the second element and ending at the given index. Syntax: _.second(array, index); Parameters: This method takes two parameters as mentioned above and described below: array: The given array from the
3 min read
Lodash _.best() Method
The Lodash _.best() method takes an array and a function and generates the best suitable value from that array using the conditions of the function. Syntax: _.best(array, function) Parameters: This method accepts two parameters as mentioned above and described below: array: The given array from which the best value is calculated.function: The funct
2 min read
Lodash _.third() Method
The Lodash _.third() method takes an array and an index and hence returns an array generated by taking elements from the original array starting with the third element and ending at the given index. Syntax: _.third(array, index); Parameters: This method takes two parameters as mentioned above and described below: array: The given array from the ele
3 min read
Lodash _.constant() Method
Lodash is a JavaScript library that works on the top of underscore.js. Lodash helps in working with arrays, strings, objects, numbers, etc. The _.constant method is used to create a function that returns value. Syntax: _.constant(value) Parameters: This method accepts one parameter as mentioned above and described below: value: The value to return
1 min read
Lodash _.invoke() 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 _.invoke() method is invoked the method at path of object. Syntax: _.invoke(object, path, args) Parameters: This method accepts three parameters as mentioned above and described b
2 min read
Lodash _.cons() Method
The Lodash _.cons() Method is used to construct a new array by taking some element and putting it at the front of another array or element. Syntax: _.cons(element, Array_or_element); Parameters: element: It is the element that gets put in the front to construct a new Array.Array_or_element: It is the second parameter used to construct an array. Ret
2 min read
Lodash _.iterateUntil() Method
The Lodash _.iterateUntil() Method takes two functions, one is used as a result generator, other function used as a stop-check and a seed value say n and returns an array of each generated result. The operation of _.iterateUntil() method is such that the result generator is passed with the seed value at the start and each subsequent result which wi
2 min read
Lodash _.first() Method
The _.first() method is used to get the first element of the specified array. Syntax: _.first(array) Parameters: This method accepts a single parameter as mentioned above and described below: array: This parameter holds an array to query. Return Value: This method returns the first element of the array. Example 1: C/C++ Code // Defining Lodash vari
1 min read
Lodash _.entriesIn() Method
The _.entriesIn() method is used to create an array of own and inherited enumerable string keyed-value pairs for the specified object. If object is a map or set, its entries are returned. Syntax: _.entriesIn(object) Parameters: This method accepts a parameter as mentioned above and described below: object: This parameter holds the object to query.
1 min read
Lodash _.extend() Method
The _.extend() method is like the _.assign() method except that it iterates over its own and inherited source properties. Syntax: _.extend(object, sources) Parameters: This method accepts two parameters as mentioned above and described below: object: This parameter holds the destination object.sources: This parameter holds the source objects. Retur
1 min read
Lodash _.always() Method
The Lodash _.always() method takes a value and returns a function that will always return that value. Syntax: _.always( value ); Parameters: This method takes a single parameter as listed above and discussed below. value: This method takes a value to be returned. Return Value: This method returns a function. Note: To execute the below examples, you
1 min read