I have this array
const lists = [{id: 111, name: "list 1"}, {id: 332, name: 'list 2'}, ...];
From it, I want to generate an array of just list names. Here is the desired result:
["list 1", "list 2", ...]
Currently, I do this with
const list_names = lists.map(x => x.name);
and there are no problems with this code. Nor am I philosophically opposed to doing it that way. I am only asking out of curiosity: can I accomplish this using desctuturing? Something along the lines of this:
const [{name}] = [{id: 111, name: "list 1"}, {id: 332, name: 'list 2'}];
Obviously, this will only descructure the name
key of the first element of the array, but is there a way to do something like this (conceptually):
const [{[name]}] = [{id: 111, name: "list 1"}, {id: 332, name: 'list 2'}];
Also, this is NOT what I am looking for: Destructuring array of objects in es6