Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upNormative: Array.prototype.pluck #1324
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
annevk
Oct 10, 2018
Contributor
This isn't the place to propose features, see https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#new-feature-proposals.
|
This isn't the place to propose features, see https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#new-feature-proposals. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tm2josep
Oct 10, 2018
Ah okay, thanks! Also, at the risk of sounding like a total noob, do you think this is worth going through the process? I don't want to go through the whole process if it's plainly obvious that this isn't necessary.
tm2josep
commented
Oct 10, 2018
•
|
Ah okay, thanks! Also, at the risk of sounding like a total noob, do you think this is worth going through the process? I don't want to go through the whole process if it's plainly obvious that this isn't necessary. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
annevk
Oct 10, 2018
Contributor
Given that you can also write your example as arr.map(obj => obj.firstName) if I'm not mistaken, I somewhat doubt it folks will be convinced it's worth adding another method for, but who knows. Asking on the mailing list or IRC will give you an idea.
|
Given that you can also write your example as |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
littledan
Oct 10, 2018
Member
In addition to CONTRIBUTING.md, I'd recommend starting with making a library which does this, and gathering broad developer feedback, before proposing for standardization.
|
In addition to CONTRIBUTING.md, I'd recommend starting with making a library which does this, and gathering broad developer feedback, before proposing for standardization. |
tm2josep commentedOct 10, 2018
Note: I only have about a 1.5 years of professional dev experience, and am not well versed in how this sort of thing goes. Please be patient with me.
Assume we have an array of objects that are of the same schema (for lack of a better term), and wish to quickly fetch values on certain keys, pluck would allow us to do so.
Example data:
Previous solution:
New solution (with Array.prototype.pluck):
We could also make this variadic, plucking only the values we need. Although this could be done with destructing in Array.prototype.map, I think it would be convenient to have pluck instead.
Also, php supports this in the form of array_column, but it's not variadic.