Recursive filter with lodash

lodash filter
lodash deep find
lodash-es
lodash deep filter
lodash dasherize
lodash eachdeep
lodash reducer
lodash find nested object

I'd like to use the Lodash function _.filter() to filter an array of array.

I'd like to get only the firsts items that have a score with scaled is equal to 1.

var newScores = [{name: 'toto', scores: [{score: 10, scaled: 1}, {score: 10, scaled: 0}]}, {name: 'tata', scores: [{score: 500, scaled: 0}, {score: 19, scaled: 0}]}];

var filterScores = _.filter(newScores, function(score) { return _.filter(score.scores, {scaled: 1}); });

console.log(filterScores);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.core.min.js"></script>

In the inner _.filter you are trying to return a list - _.filter returns the item that evaluates to a condition so you have to set that condition.

Try adding this .length > 0; in the inner filter

var newScores = [{name: 'toto', scores: [{score: 10, scaled: 1}, {score: 10, scaled: 0}]}, {name: 'tata', scores: [{score: 500, scaled: 0}, {score: 19, scaled: 0}]}];

var filterScores = _.filter(newScores, function(score) {
  return _.filter(score.scores, {scaled: 1}).length > 0; // evaluate to a list that is not empty
});

console.log(filterScores);
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.core.min.js"></script>

How can I use Lodash/JS to recursively filter nested objects?, You could take an iterative and recursive approach. function find(id, array) { var result; array.some(o => o.id === id && (result = o) || (result� Recursive filter with lodash. Ask Question Asked 8 months ago. Active 8 months ago. Viewed 73 times 1. I'd like to use the Lodash function _.filter() to

You could take _.some in the filter callback.

var newScores = [{ name: 'toto', scores: [{ score: 10, scaled: 1 }, { score: 10, scaled: 0 }] }, { name: 'tata', scores: [{ score: 500, scaled: 0 }, { score: 19, scaled: 0 }] }],
    filterScores = _.filter(newScores, ({ scores }) => _.some(scores, { scaled: 1 }));

console.log(filterScores);
.as-console-wrapper { max-height: 100% !important; top: 0; }
<script src="https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.15/lodash.core.min.js"></script>

Lodash Documentation, var evens = _.filter([1, 2, 3, 4, 5, 6], function(num) { return num % 2 == 0; }); Recursively merges own enumerable properties of the source object(s), that don't � lodash / lodash. Watch 866 Star 44.9k Fork 4.9k Code. Issues 67. Pull requests 41. If I want to do a recursive filter, which will return the actual element

Why do you need loadash?

var newScores = [{name: 'toto', scores: [{score: 10, scaled: 1}, {score: 10, scaled: 0}]}, {name: 'tata', scores: [{score: 500, scaled: 0}, {score: 19, scaled: 0}]}];

console.log(newScores.filter(val => val.scores[0].scaled === 1));

Documentation, Recursively flatten array up to depth times. to flatten. [depth=1] (number): The maximum recursion depth. Note: Unlike _.filter , this method mutates array . reggi / lodash-recursive.md. Last active Sep 25, 2015. Star 0 Fork 0; Code Revisions 6. Embed. What would you like to do?

The proper code using lodash would be

var newScores = [{name: 'toto', scores: [{score: 10, scaled: 1}, {score: 10, scaled: 0}]}, {name: 'tata', scores: [{score: 500, scaled: 0}, {score: 19, scaled: 0}]}];

var filterScores = _.filter(newScores, function(score) { return score.scores[0].scaled === 1 });

console.log(filterScores);

How can I use Lodash/JS to recursively filter nested objects?, lodash filter nested array lodash online lodash pickby recursive lodash/fp lodash flatten nested object lodash map nested object. I have an array with objects of� _.merge in lodash as a means to recursively merge down objects. These days I have been exploring all the options out there when it comes to merging down two or more objects into a single object. There are many ways to go about doing it that have different effects, there is the idea of just copying over key values, or just referencing them even.

lodash orderBy recursive Code Example, Get code examples like "lodash orderBy recursive" instantly right from your google search results with the Grepper Chrome Extension. Lodash's map method works exactly like Javascript native array method except that it has a sweet upgrade. It's able to navigate deeply-nested property by just providing a string instead of a callback function. Take note: There is a much more specific method for this use-case: _.pluck. Apparently _.pluck will be removed in

Deepdash, Check if path exists in the object considering sparse arrays. Unlike Lodash's has - exists returns false for empty array slots. _.exists( obj, path ) => boolean. Using .filter() and making a recursive call as I described in the comment above is basically what you need. You just need to update each .children property with the result of the recursive call before returning. The return value is just the .length of the resulting .children collection, so if there's at least one, the object is kept.

Deep pick using lodash/underscore, Requirements. Recursively apply a pick to each level in an object. If a property is an object / array ,� The lodash _.map method If you work with javaScript a lot like I do chances are you are going to be aware of many of the methods that are part of the Array prototype, one of which is Array.map. In lodash there is also the _.map method what works just like that only it is a little more advanced.