Skip to content
Advertisement

How to filter object based on conditional argument?

I am calling a function with two arguments,

Arg 1: Object {a:1, b:2, c:3, d:4}

Arg 2: Condition ((prop, key) => prop >= 3))

Here based on the condition we need to filter the object and provide the result as array of objects.

The code that I have tried,

JavaScript

Current Result: [3,4]

Expected Result: [{c:3}, {d:4}]

Advertisement

Answer

You could get the entries, filter by handing over the right format for filtering function and build objects of filtered entries.

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