Skip to content

Tag: underscore.js

Updating nested object by path in javascript

Let’s say I have this object: I’d like to be able to update the price in this object through a function call as follows: This answer Javascript: how to dynamically create nested objects using object names given by an array is good but does not address the case when there are arrays in the object. …

Remove empty objects from an object

I am trying to remove empty objects inside an object, here is an example with the expected output: I tried using some examples from other StackOverflow questions, however those are just for one level objects. Answer Basic function that removes empty objects First start with a function that only works with a s…

Add property to an array of objects

I have an array of objects as shown below I want to add one more property named Active to each element of this array of Objects. The final outcome should be as follows. Can someone please let me know how to achieve this. Answer You can use the forEach method to execute a provided function once for each elemen…

_.chain – underscore JS

This code works fine Is it possible to use the _.chain() function to clean this code up? I’ve tried to code below, but it gives a Type error. Answer You just need to remove the first argument (arr) from each of the functions you have inside the _.chain() and _.value() (as they are now gather from the ch…