Enumerating JavaScript Objects: Understanding the for in Loop

Поделиться
HTML-код
  • Опубликовано: 18 ноя 2024

Комментарии • 11

  • @nageshthotakura8758
    @nageshthotakura8758 3 года назад

    A Great Javascript Channel. Thank you for your efforts. May God Bless You.

  • @amguruprasath8037
    @amguruprasath8037 5 лет назад +2

    simple beautiful and in-depth. You're doing a great service thank you!

  • @salimahusain5819
    @salimahusain5819 4 года назад

    I had an object with 218 attributes that i set and I wanted to loop through all of them and I thought I would have to *make* an array of all the attribute names. You saved me so much time. Thank you.

  • @heathergarcia9946
    @heathergarcia9946 6 лет назад +2

    Thank you so much for this video! I was stuck on some "for in loop" challenge questions @ school and this video helped me solve the questions.

  • @shabnamnaaz4676
    @shabnamnaaz4676 4 года назад

    your videos are really unique, thankyou steven :) .

  • @nwobodogeorge5370
    @nwobodogeorge5370 4 года назад

    Thank you for the teaching. I learnt a lot from it.

  • @derkvanderveen8938
    @derkvanderveen8938 4 года назад

    Thanks, very clear explanation.

  • @derrickdbrandon
    @derrickdbrandon 5 лет назад

    Extremely helpful, thank you!

  • @batchrocketproject4720
    @batchrocketproject4720 Год назад

    I experimented with adding named properties to array objects and they are enumerated with the for-in loop. The inbuilt .length property is not (and ar.propertyIsEnumerable("length") returns false). I attempted to set the .length property's enumerable attribute to true (using ar.length.enumerable = true;). When I checked its enumerability with ar.propertyIsEnumerable("length"), the return value is true. However, when I repeated the for-in loop on the array, the length property was ignored. I remain confused by this and would appreciate any insight.

    • @AllThingsJavaScript
      @AllThingsJavaScript  Год назад

      You can't change the attribute of a property using this technique. You need to use Object.defineProperty(). However, the configurable attribute of the length property is set to false. This means you can't make any changes to its attributes. I hope that helps.