const id = person.id;
const firstName = person.firstName;
const lastName = person.lastName
const age = person.age;
So, no, you can’t do that, destructing is for pulling values out. As it is, the thing you’re asking for is essentially what you have already: you can just do console.log(people) (or console.log(JSON.stringify(people)))
Well, you can’t do that from just destructing – destructuring assigns a set of variables, and they have arbitrary names. You can’t get the name of a variable from a variable, that can’t possibly work.
You can get the values, and write them out, like
const myObject = {
foo: 1,
bar: 2,
};
const { foo, bar } = myObject;
console.log(`
foo: ${foo}
bar: ${bar}
`);
Although that seems a little pointless.
You can’t really replace a loop with destructuring, they’re not equivalent things.