gpt-4-0314· OpenAI
WildChat-4.8M (AI2)
I have…
- User
I have data:[{mname:001,111:123,113:321,134:654,135:456,136:1554,101:56800,109:0,115:0},{mname:006,111:113,113:3211,134:154,135:156,136:154,101:5800,109:10,115:1000}]
I need formatting data: [{001,{111:123,113:321,134:654,135:456,136:1554,101:56800,109:0,115:0}},{006,{111:113,113:3211,134:154,135:156,136:154,101:5800,109:10,115:1000}}] Please use javascript
- Assistantjs
let data = [ { mname: "001", 111: 123, 113: 321, 134: 654, 135: 456, 136: 1554, 101: 56800, 109: 0, 115: 0 }, { mname: "006", 111: 113, 113: 3211, 134: 154, 135: 156, 136: 154, 101: 5800, 109: 10, 115: 1000 } ]; let formattedData = data.map(({ mname, ...rest }) => ({ [mname]: rest })); console.log(formattedData);This code snippet maps the original data array to the new format by destructuring the
mnameproperty fromrestof the properties in each object. Then, it constructs a new object with the desired format where{ [mname]: rest }.