map修改原来数组的值,合并返回新的数组

map修改原来数组的值,合并返回新的数组(map需要return)

把res数据里面的id 和 datainfo数据,合并成一个数组返回来

  let res = [
        {
          _id: 1,
          _openid: "oaGo44309bgk9Rsku_pXvENYmzws",
          datainfo: {
            address: "南京市",
            avatarUrl:
              "https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4…cVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132",
            classdata: "景点",
            nickName: "微信用户",
            openid: "oaGo44309bgk9Rsku_pXvENYmzws",
            staticimg: ["1.png", "2.png", "3.png"],
            time: "2022-07-15 09:12:01",
            tipsdata: "这个地方适合小朋友过来玩耍,里面有很多小动物",
            titledata: "红山动物园",
          },
        },
        {
          _id: 2,
          _openid: "oaGo44309bgk9Rsku_pXvENYmzws",
          datainfo: {
            address: "南京市",
            avatarUrl:
              "https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4…cVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132",
            classdata: "景点",
            nickName: "微信用户",
            openid: "oaGo44309bgk9Rsku_pXvENYmzws",
            staticimg: ["1.png", "2.png", "3.png"],
            time: "2022-07-15 09:12:01",
            tipsdata:
              "南京欢乐谷一日游就是排队一小时,玩耍一分钟,基本上一天都在天上度过了,回去赶快收拾就睡了,真的太累了。但是还是很开心的!",
            titledata: "南京欢乐谷",
          },
        },
        {
          _id: 3,
          _openid: "oaGo44309bgk9Rsku_pXvENYmzws",
          datainfo: {
            address: "南京市",
            avatarUrl:
              "https://thirdwx.qlogo.cn/mmopen/vi_32/POgEwh4mIHO4…cVGKSyXwibcPq4BWmiaIGuG1icwxaQX6grC9VemZoJ8rg/132",
            classdata: "网红打卡",
            nickName: "微信用户",
            openid: "oaGo44309bgk9Rsku_pXvENYmzws",
            staticimg: ["1.png", "2.png", "3.png"],
            time: "2022-07-15 09:12:01",
            tipsdata: "出来放松一下,鸽子好多啊,nice",
            titledata: "音乐台",
          },
        },
      ];
      //把res数据里面的id 和 datainfo数据,合并成一个数组返回来
      let newres = res.map((item) => {
        let id = item._id;
        let datainfo = item.datainfo;
        return {
          id,
          datainfo,
        };
      });
      console.log(newres);

你可能感兴趣的:(javascript)