How can I map over two arrays at the same time?

前端 未结 2 1875
清歌不尽
清歌不尽 2020-12-30 09:55

I have two arrays, one with urls and one with content. They look like this:

const link = [ \'www.test0.com\', \'www.test1.com\', \'www.test2.com\' ]
const c         


        
2条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-30 10:09

    You would be better off having it as:

    const data = [
        { link: "www.test0.com", text: "this is test0 content" },
        { link: "www.test1.com", text: "this is test1 content" }
    ];
    

    You would then render content like:

    render() {
        var links = [];
        for (var i = 0; i < data.length; i++) {
            var item = data[i];
            links.push(
    {item.text}
    ); } return (
    {links}
    ); }

    Please note, this is untested code as I don't have a JSX project currently setup that I can test it in.

提交回复
热议问题