Given is the response data’s following data structure …
const res = {
data: [{
name: 'c2',
ipaddr: '192.168.1.5',
port: 4435,
sshuser: "abc",
sshpass: "xyz",
sshport: 22,
license: 'license.txt',
}],
};
I want to convert it to …
const newState = [{
name: 'c2',
ipaddr: '192.168.1.5',
port: 4435,
}, {
sshuser: "abc",
sshpass: "xyz",
sshport: 22,
}, {
license: 'license.txt',
}]
The below posted code does achieve the expected result …
var obj1 = {
name: res.data[0].name,
ipaddr: res.data[0].ipaddr,
port: res.data[0].port,
};
var obj2 = {
sshuser: res.data[0].sshuser,
sshpass: res.data[0].sshpass,
sshport: res.data[0].sshport,
};
var obj3 = {
license: res.data[0].license,
};
const newState = [obj1, obj2, obj3];
What are other ways of achieving the same result, maybe using a shorter syntax?