for (let key of Object.keys(obj)) { ... }

On Fri, Mar 4, 2016 at 4:48 PM, Langdon <[email protected]> wrote:

> Ah, thanks.  I had forgotten about Object.keys, but even that still
> doesn't wrap things up as nicely as `forIn`.
>
> Object.entries looks nice.
>
> On Fri, Mar 4, 2016 at 11:37 AM, Logan Smyth <[email protected]>
> wrote:
>
>> You can already achieve this in ES5 with
>>
>> ```
>> Object.keys(obj).forEach(key => {
>>
>> });
>> ```
>>
>> or in ES6 with
>>
>> ```
>> var key;
>> for (key of Object.keys(obj)){
>>
>> }
>> ```
>>
>> And with the new proposal, you'll also have `Object.values` for values
>> and `Object.entries` for key/value pairs:
>> https://github.com/tc39/proposal-object-values-entries
>>
>> On Fri, Mar 4, 2016 at 8:22 AM, Langdon <[email protected]> wrote:
>>
>>> My apologies if this has been discussed before (I have to imagine it
>>> has, but couldn't find anything).
>>>
>>> Why isn't there a `forIn` method on Object natively?
>>>
>>> Something that simply wraps this all-to-common code:
>>>
>>>
>>> var key;
>>>
>>> for (key in obj) {
>>>   if (obj.hasOwnProperty(key) === true) {
>>>     ...
>>>   }
>>> }
>>>
>>> Example: https://jsfiddle.net/langdonx/d4Lph13u/
>>>
>>> TIA,
>>> Langdon
>>>
>>> _______________________________________________
>>> es-discuss mailing list
>>> [email protected]
>>> https://mail.mozilla.org/listinfo/es-discuss
>>>
>>>
>>
>
> _______________________________________________
> es-discuss mailing list
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to