DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 968,547 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for Push Object to a Paired Array
Jackson Reeves
Jackson Reeves

Posted on

Push Object to a Paired Array

Pushing an object from one array into another array’s object is tricky, especially if you don’t know how many elements are in each array or where each one might be found. If both objects in question happen to share a common key-value pair, then you can use this approach. You’ll end up giving the main array’s object a new key and setting its value to the other array’s object. You can achieve all of that with two for loops that iterate over both arrays separately plus an if conditional.

For more details about this technique (and alternative solutions to its underlying problem), check out this Stack Overflow answer that ultimately put me on the right track.

Top comments (0)

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›