Skip to content
Advertisement

Tag: underscore.js

How can I make Underscore behave like Ramda?

Two days ago, I announced a preview release of Underscore that integrates with the new Node.js way of natively supporting ES modules.1 Yesterday, somebody responded on Twitter with the following question: Can you do Ramda-style data last functions? He or she was referring to one of the main differences between Underscore and Ramda. In Underscore, functions typically take the data

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. Underscore acceptable. Note: this answer

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 single level of nesting. This function removes all

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 element in

_.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 chain): And you

Advertisement