第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何使用地圖或 JavaScript 中的其他方法創(chuàng)建自定義數(shù)組?

如何使用地圖或 JavaScript 中的其他方法創(chuàng)建自定義數(shù)組?

萬千封印 2023-11-11 20:54:11
我有從后端帶來的這個(gè)數(shù)組:[{  timeDate: '2020-12-10T06:00:00.535+00:00',  totTransApproved: 75,  totTransDeclined: 3,  totAmount: 5016}, {  timeDate: '2020-12-10T06:01:00.535+00:00',  totTransApproved: 71,  totTransDeclined: 4,  totAmount: 11337}, {  timeDate: '2020-12-10T06:02:00.535+00:00',  totTransApproved: 83,  totTransDeclined: 6,  totAmount: 14370}]我需要將其轉(zhuǎn)換為這種形式:[{  timeDate: '12/04/20 0:00',  name: 'Approved',  totTrans: 180,  totAmount: 125,}, {  timeDate: '12/04/20 0:00',  name: 'declined',  totTrans: 10,  totAmount: 12,}]我已經(jīng)嘗試過這種方式,但我需要兩個(gè)對象const datums = records.map((item) => ({  timeDate: item.timeDate,  name: 'Aprobada',  totTrans: item.totTransApproved,  totAmount: item.totAmount,}));我該怎么做 ?
查看完整描述

1 回答

?
絕地?zé)o雙

TA貢獻(xiàn)1946條經(jīng)驗(yàn) 獲得超4個(gè)贊

我認(rèn)為您的意思是您想要將輸入中的每個(gè)對象拆分為單獨(dú)的“已批準(zhǔn)”和“已拒絕”對象。如果這是正確的,您可以從map()


const records = [{timeDate: '2020-12-10T06:00:00.535+00:00',totTransApproved: 75,totTransDeclined: 3,totAmount: 5016}, {timeDate: '2020-12-10T06:01:00.535+00:00',totTransApproved: 71,totTransDeclined: 4,totAmount: 11337}, {timeDate: '2020-12-10T06:02:00.535+00:00',totTransApproved: 83,totTransDeclined: 6,totAmount: 14370}]


const datums = records.map((item) => (

  [

    { timeDate: item.timeDate,

      name: 'Approved',

      totTrans: item.totTransApproved,

      totAmount: item.totAmount

    },

    { timeDate: item.timeDate,

      name: 'Declined',

      totTrans: item.totTransDeclined,

      totAmount: item.totAmount

    }

  ]

  ));

  

  console.log(datums);

.as-console-wrapper { max-height: 100% !important; top: 0; }


或者,如果您不希望它們按數(shù)組分組,請使用flatMap()展平返回的對象數(shù)組。


const datums = records.flatMap((item) => (

  [

    { timeDate: item.timeDate,

      name: 'Approved',

      totTrans: item.totTransApproved,

      totAmount: item.totAmount

    },

    { timeDate: item.timeDate,

      name: 'Declined',

      totTrans: item.totTransDeclined,

      totAmount: item.totAmount

    }

  ]

  ));


查看完整回答
反對 回復(fù) 2023-11-11
  • 1 回答
  • 0 關(guān)注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號