0

In React Native JSX, how can join two map of strings like this?

const map1 = { title: 'Avengers: Infinity War', genre: 'Action, Adventure, Fantasy' };
const map2 = { directors: 'Anthony Russo, Joe Russo', stars: ' Robert Downey Jr., Chris Hemsworth, Mark Ruffalo' };

The result I want:

{ title: 'Avengers: Infinity War', genre: 'Action, Adventure, Fantasy',  directors: 'Anthony Russo, Joe Russo', stars: ' Robert Downey Jr., Chris Hemsworth, Mark Ruffalo' }

Thanks for your help!

0

2 Answers 2

1

const map1 = { title: 'Avengers: Infinity War', genre: 'Action, Adventure, Fantasy' };
const map2 = { directors: 'Anthony Russo, Joe Russo', stars: ' Robert Downey Jr., Chris Hemsworth, Mark Ruffalo' };

console.log(Object.assign({}, map1, map2));

Object.assign({}, map1, map2);
Sign up to request clarification or add additional context in comments.

Comments

1

You can just use the object spread ... syntax:

const mergedMaps = {...map1, ...map2}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.