账号密码登录
微信安全登录
微信扫描二维码登录

登录后绑定QQ、微信即可实现信息互通

手机验证码登录
找回密码返回
邮箱找回 手机找回
注册账号返回
其他登录方式
分享
  • 收藏
    X
    js有个list列表,需要转化成想要的数据结构
    29
    0
    var list = [
        {recipient: 'abccccccc', type: '0x2', amount: 1, time: '2019-07-04 09:00:00', flag: '加入'}, //加入委托
        {recipient: 'abccccccc', type: '0x3', amount: 0, time: '2019-07-04 09:01:00', flag: '退出'}, //退出委托
        {recipient: 'abccccccc', type: '0x2', amount: 2, time: '2019-07-04 09:02:00', flag: '加入'}, //加入委托
        {recipient: 'abccccccc', type: '0x3', amount: 0, time: '2019-07-04 09:03:00', flag: '退出'}, //退出委托
        {recipient: 'abccccccc', type: '0x2', amount: 3, time: '2019-07-04 09:04:00', flag: '加入'}, //加入委托
        {recipient: 'abccccccc', type: '0x3', amount: 0, time: '2019-07-04 09:05:00', flag: '退出'}, //退出委托
    ]
    

    一顿操作后想要得到的数据结构

    var list = [
        {recipient: 'abccccccc', type: '0x2', amount: 1, time: '2019-07-04 09:00:00', flag: '加入'}, //加入委托
        {recipient: 'abccccccc', type: '0x3', amount: 1, time: '2019-07-04 09:01:00', flag: '退出'}, //退出委托
        {recipient: 'abccccccc', type: '0x2', amount: 2, time: '2019-07-04 09:02:00', flag: '加入'}, //加入委托
        {recipient: 'abccccccc', type: '0x3', amount: 2, time: '2019-07-04 09:03:00', flag: '退出'}, //退出委托
        {recipient: 'abccccccc', type: '0x2', amount: 3, time: '2019-07-04 09:04:00', flag: '加入'}, //加入委托
        {recipient: 'abccccccc', type: '0x3', amount: 3, time: '2019-07-04 09:05:00', flag: '退出'}, //退出委托
    ]
    

    这边要通过time字段的值,先后得到amount相对应的字段

    0
    打赏
    收藏
    点击回答
    您的回答被采纳后将获得:提问者悬赏的 10 元积分
        全部回答
    • 0
    • AI智能解答 超级管理员 2023-04-06 12:131楼
      ```javascript let list = [1, 2, 3, 4, 5]; let newList = {}; list.forEach(item => { newList[item] = item; }); console.log(newList); ```
    更多回答
    扫一扫访问手机版
    • 回到顶部
    • 回到顶部