cpongo8
大盗零妖 qaq
采纳率37.5%
2020-10-28 15:43 阅读 77

js小技巧数据格式化??

5

,{$dt1$: "'2020-10-21'", $dt2$: "'2020-10-26'"} 变成[{name: "dt1", value: "'2020-10-21'"},{name: "dt2", value: "'2020-10-26'"}] 用最简单的方式 最简短的代码实现,大家有什么好的方法可以贴出来

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • dsxjinzhiqiang dsxjinzhiqiang 2020-10-30 09:20
        var obj={$dt1$: "'2020-10-21'", $dt2$: "'2020-10-26'"}
            var list=[]
            for (var i in obj) {
                list.push({
                    name:i.replaceAll('$',''),
                    value:obj[i]
                })
            }
            console.log(list)
    

    图片说明

    点赞 评论 复制链接分享
  • z1259678404 Nacl.Zz 2021-03-01 14:28
    const origin = { $dt1$: "'2020-10-21'", $dt2$: "'2020-10-26'" }
    
    const result = Object.keys(origin).map(key => {
    	return {
    		name: key.replace(/\$/g, ''),
    		value: origin[key]
    	}
    })
    
    点赞 评论 复制链接分享

相关推荐