[SOLVED] Need some javascript help merging array please

Hey Guys need some help joining two arrays for mapping .

socialMedia = [
  {
    id: 1,
    name: "Twitter",
    cName: "explore-col-title-links-icons",
    icon: <Twitter />,
  },
  {
    id: 2,
    name: "Discord",
    cName: "explore-col-title-links-icons",
    icon: <Discord />,
  },
  {
    id: 3,
    name: "Telegram",
    cName: "explore-col-title-links-icons",
    icon: <Telegram />,
  },
  {
    id: 4,
    name: "Website",
    cName: "explore-col-title-links-icons",
    icon: <Globe />,
  },
  {
    id: 5,
    name: "Medium",
    cName: "explore-col-title-links-icons",
    icon: <Medium />,
  },
];

Object 2 is 
[
  { link: 'https://twitter.com/xxx' },
  { link: 'https://discord.com/invite/xxx' },
  { link: 'https://t.me/xxx' },
  { link: 'https://www.xxx.co/' },
  { link: 'https://medium.com/@nxxx' }
]
The Result im looking for  ===>
socialMedia = [
  {
    id: 1,
    name: "Twitter",
    cName: "explore-col-title-links-icons",
    icon: <Twitter />,
    link: 'https://twitter.com/xxx' ,

  },
  {
    id: 2,
    name: "Discord",
    cName: "explore-col-title-links-icons",
    icon: <Discord />,
    link: 'https://discord.com/invite/xxx'
  },
  {
    id: 3,
    name: "Telegram",
    cName: "explore-col-title-links-icons",
    icon: <Telegram />,
    link: 'https://t.me/xxx'
  },
  {
    id: 4,
    name: "Website",
    cName: "explore-col-title-links-icons",
    icon: <Globe />,
    link: 'https://www.xxxs.co'
  },
  {
    id: 5,
    name: "Medium",
    cName: "explore-col-title-links-icons",
    icon: <Medium />,
   link: 'https://medium.com/@nxxx' 
  },
];

im trying this code but the return on the last links in all array link: ‘https://medium.com/@nxxx’

 let result = [];

  socialMedia.forEach((element) => {
    for (let i = 0; i < 5; i++) {
      element.link = ext_links[i].link;
    }
    result.push(element);
  });

try to do a simple for and not a forEach
like you are doing the second for with ext_links[i] to access an index

and then try to create a new array with all the results

1 Like

got it to work thanks for help learning alot with you guys :heart: :slight_smile:

 let result = [];
  for (let i = 0; i < 5; i++) {
    const data = {
      name: socialMedia[i].name,
      icon: socialMedia[i].icon,
      cName: socialMedia[i].cName,
      link: ext_links[i].link,
    };

    result.push(data);
  }```
1 Like