Object Array Pick

I couldn't find a better name.

Just a small idea of picking props off an object and smashing them into an array.

const person = {
  age: 12,
  name: "Ethan",
};

person.["age", "name"]; // [12, "Ethan"]

I've seen this idea that shows a similar way to get a subset of an object. If it will exist, why shouldn't this? I find it like having object destructuring but not array destructuring.

Any thoughts?

PS: I happen to have given the 400th post!

PS: I didn't use person["age", "name"] because for some reason it happens to be valid JS.

Perhaps there's use cases for a syntax like this, but I can't think of any time when I've had an object, and I wanted to put specific property values into a specific order in an array like this.

Can you think of any use cases for such a syntax?

1 Like

['age', 'name'.map(x => person[x]) is not much longer than your suggested example and follows existing JS idioms.

I also have never seen a use case for this, though, and would love to hear more.

1 Like