Skip to content
Advertisement

Searching Objects for Values and placing into new array

I’m attempting to search each of the objects listed below from my dataset to see if they contain a value and if they do have that value to add the entire object into a new array.

Example:

Search List of Objects for Data “Continuous”, if that data exists (Which it does in Doormerica and Hager) then take the entire object “Doormerica” and “Hager” and put the entire thing into a new array.

JavaScript

Advertisement

Answer

Data Transformation

I decided to post this solution because the question asks how to “take the entire object”. And including the name (Doormerica, Hager, etc.) in the result, either as a key or a value, seems an important part of the transformation. And we can accomplish this in one pass using Object.entries(), Array.reduce(), Spread Syntax, and the appropriate transformation code.

Examples of both transformations

JavaScript

Snippet

The snippet shows the complete code for doing both transformations.

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