Skip to content
Advertisement

Lodash to check object property on array elements

I want to use lodash to find a property of an object at a specific array element.

Lets say I am hitting an api and getting response which sets it to the react state “personsDetails” (whose initial value was null), so now it becomes

JavaScript

now when i want to access “name” property of 2nd object i do

JavaScript

So is there any shorted syntax of accessing it via using lodash ? If the values doesnt exist i need null

As far as i know _get property works with object only so here i am dealing with array and then object

Advertisement

Answer

You can still use get and set the default as null

JavaScript
JavaScript

or can use nth along with get and set the default as null

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement