在React Native JSX中,如何连接两个这样的字符串映射?
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' };
我想要的结果
{ title: 'Avengers: Infinity War', genre: 'Action, Adventure, Fantasy', directors: 'Anthony Russo, Joe Russo', stars: ' Robert Downey Jr., Chris Hemsworth, Mark Ruffalo' }
感谢您的帮助!
答案 0 :(得分: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);
答案 1 :(得分:1)
您可以只使用对象传播...
语法:
const mergedMaps = {...map1, ...map2}