Skip to content

Tag: lodash

Checking ‘undefined’ or ‘null’ of any Object

I am working on Angular project and time to time I used to have check undefined or null over Object or it’s properties. Normally I use lodash _.isUndefined() see example below: I couldn’t see any problem with it. But I had discussion with my colleague during review of above code. He was telling me…

Conditionally concatenate in reducer using lodash

I try to conditionally concat in my reducer, I have an array objects and I want to concatenate only if value not exist in my reducer. If value exists nothing must happen. I use lodash and I tried with _.uniqBy like this : This does not work. Example of my reducer jsFiddle linkk Required output : Because val1 …

Lodash _.set only if object exists

I am looking to set inner properties of an object only if they already exist. Lodash _.set will create the whole hierarchy if it does not exist. Is there an easy way to do this ? (Without and if statement ?) Snippet below: Answer The answer from Kalaiselvan A below put me on the way but this is not quite

How to Import a Single Lodash Function?

Using webpack, I’m trying to import isEqual since lodash seems to be importing everything. I’ve tried doing the following with no success: Answer You can install lodash.isequal as a single module without installing the whole lodash package like so: When using ECMAScript 5 and CommonJS modules, you…

use Lodash to sort array of object by value

I am trying to sort an array by ‘name’ value (using Lodash). I used the Lodash docs to create the solution below however .orderBy doesn’t seem to be having any affect at all. Can anyone shed some light on the correct way to sort array? Chars Array Function Code Answer This method orderBy doe…

Lodash – Find deep in array of object

I have an array of an object like this What I need is sum the property Val when prop is foo. So, I have to search through elements and get all objects where prop is foo. With this objects, I should sum the val property. I tried to use many combinations of _.find, _.pick and so on, but I don’t