Here is the data structure for the response data:
const res = {
data: [{
name: 'c2',
ipaddr: '192.168.1.5',
port: 4435,
sshuser: "abc",
sshpass: "xyz",
sshport: 22,
license: 'license.txt',
}],
};
I need to transform it into the following format:
const newState = [{
name: 'c2',
ipaddr: '192.168.1.5',
port: 4435,
}, {
sshuser: "abc",
sshpass: "xyz",
sshport: 22,
}, {
license: 'license.txt',
}]
The code below successfully achieves the desired outcome:
const newState = [{name: res.data[0].name, ipaddr: res.data[0].ipaddr, port: res.data[0].port},{sshuser: res.data[0].sshuser, sshpass: res.data[0].sshpass, sshport: res.data[0].sshport},{license: res.data[0].license}];
Are there alternative methods to achieve the same result, perhaps with a more concise syntax?