Object.entries(), Object.values()
You can make a PR at tc39/agendas Very much like I did there tc39/agendas#27
C. Scott Ananian wrote:
propose these for ES6/ES7?
David's reply covers the main stuff, but on this question, let's be clear: ES6 is wrapped up and being edited and implemented. ES7 is fair game. Engines can implement both, so there's no reason to worry that you won't see Object.values or Object.entries for years in modern browsers. But we need to get it into consensus-ES7.
On Wed, Mar 19, 2014 at 2:08 PM, C. Scott Ananian <ecmascript at cscott.net>wrote:
Or maybe just mentioning @rwaldron is enough to magically make it appear on an agenda. ;)
I will gladly champion this for ES7.
Won't this create a subtle false symmetry? For the collection types, "keys", "entries", and "values" return iterators, but in this case "Object.keys" would have to return an array. Does that matter?
Hmm. It definitely affects the behavior when properties are added or removed during iteration.
Map and Set iterators are "live". But then, Map and Set iteration is fully specified and deterministic. That's not in the cards for property enumeration. So "live" iterators over object properties would, I'm sure, end up being less compatible across implementations than arrays, in those mutating cases.
Because of that, and because Object.keys already returns an array, I think Object.values and Object.entries should too.
-j
P.S. Separately, I just noticed that you can say: new Map(Object.entries(obj))
. That Map constructor was designed to
compose; nice to see that it works.
On Fri, Mar 21, 2014 at 10:10 AM, Jason Orendorff <jason.orendorff at gmail.com> wrote:
Because of that, and because Object.keys already returns an array, I think Object.values and Object.entries should too.
I agree. This is also consistent with the arrays returned by getPropertyDescriptors and the proxy trap (which I believe was also going to be changed from an iterator to an array).
It's not an iterator, but it's still an iterable. It should work
seamlessly in common cases such as new Map(Object.entries(obj)
(which happens to be the use case I was thinking of in particular when
I wrote the OP) and Array.from(Object.entries())
(which is pointless
in itself, but we might start seeing Array.from
in generic contexts
to snapshot possible iterators/iterables).
getPropertyDescriptors should not return an array at all but an object with all keys/symbols so it can be reused to defineProperties later on ... right?
'cause I don't see why getPropertyDescriptors would return an Array otherwise ..
The version I have on the agenda, that you wrote, returns an object. No disrespect to you, but this is irrelevant to the current thread.
the version in agenda is about getOwnPropertyDescriptors ... I thought it
is relevant to not mess up too much with what same method without the Own
part also because I don't know why, getPropertyDescriptors, would return an
Array, except just as simulation of the Java meaning?
Or rephrasing: what is a list of descriptors useful for in ES7?
also ... as side note, why this came back to me when the topic is Object.values I didn't go off topic, I just asked a clarification of a mentioned method that has nothing to do with values?
Anyway ... off the thread again, I didn't mean to bring irrelevant discussions in here ...
On Fri, Mar 21, 2014 at 4:02 PM, Andrea Giammarchi < andrea.giammarchi at gmail.com> wrote:
the version in agenda is about getOwnPropertyDescriptors ... I thought it is relevant to not mess up too much with what same method without the
Own
part also because I don't know why, getPropertyDescriptors, would return an Array, except just as simulation of the Java meaning?
I just assumed getPropertyDescriptors was a mistyped. Sorry for the noise. I don't think they should deviate from each other.
Sorry for the confusion. I was actually referring to [[OwnPropertyKeys]] returning an Array, as discussed previously: esdiscuss.org/topic/object-getownpropertydescriptors-o-plural#content-34
Presumably the corresponding proxy trap would change to return an Array as well.
But this is a bit off-topic for Object.entries/Object.values --- although related in the sense that the "[[OwnPropertyKeys]] returns Array" proposal also got support (and a +1 from be) on the list, but hasn't been formally added to the ES6 agenda as far as I can tell.
Thanks for digging this up. I'll add it to the agenda.
We briefly mentioned
Object.entries
/Object.values
the other day on list (to complementObject.keys
).Is there any concrete plan to propose these for ES6/ES7? Would filing a bug help? Or maybe just mentioning @rwaldron is enough to magically make it appear on an agenda. ;)