json = '{"squadName":"Super hero squad","homeTown":"Metro City","formed":2016,"secretBase":"Super tower","active":true,"members":[{"name":"Molecule Man","age":29,"secretIdentity":"Dan Jukes","powers":["Radiation resistance","Turning tiny","Radiation blast"]}]}';
data = JSON.parse(json);
console.log(data);
const {squadName, homeTown, formed, secretBase, active} = data;
console.log(squadName, homeTown, formed, secretBase, active)
In the above scenario, how do I get squadName, homeTown, formed, secretBase, active
into variables with the same names without having to hard code the const {squadName, homeTown, formed, secretBase, active} = data;
part?
Is it possible to create the const {squadName, homeTown, formed, secretBase, active}
part dynamically from the json data by using it's keys and the use it like const {squadName, homeTown, formed, secretBase, active} = data