Playing with JavaScript Objects

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

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

  • @lenomarin3484
    @lenomarin3484 8 лет назад +5

    It would be helpful if you could walk through how objects within objects (or functions within objects) can be called and updated.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  8 лет назад +4

      Thanks for the suggestion. I will add that to my list of future videos.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  7 лет назад +23

      I have added that video now if you are still interested - ruclips.net/video/AqgVLYpBWG8/видео.html

    • @khaledfarghly6480
      @khaledfarghly6480 3 года назад +3

      @@SteveGriffith-Prof3ssorSt3v3 you'r really good man and perfect teacher.

  • @rotrose7531
    @rotrose7531 4 года назад +5

    Though still half way in the journey of following your tutorials, many fogs in my head for many years have been cleared. Thank you.

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

    first time I run into tutorials like these, unique explanation, clear and calm voice well done man hope to see more like this

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

    Steve, you are amazing. You talk slowly and calm and clear. Your voice has a very calm sound and makes me want to listen to you even if you describe how to vivisect a frog. Plus, your name just reminded me that it is many months I didn't check if there is any new Berserk chapter out.

  • @akemim.7854
    @akemim.7854 4 года назад +1

    Another great video, Steve! I'm watching almost all of your videos throught my learning journey with JS. If I need to understand better a specific concept, I hurry to your channel. Keep going, you're doing an amazing job! 🤗 💖

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

    Thanks Steve! You make excellent tutorials that are very clear and easy to follow.

  • @ozzyfromspace
    @ozzyfromspace 5 лет назад +1

    The fact that objects automatically update everywhere they are located is truly amazing!

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

    Amazing! Thanks for your clear explanations.🌹

  • @anitag6925
    @anitag6925 4 года назад +2

    I know this is an older video but could you explain a bit more about why just adding the line dog["age"]=14 didn't work? Woody was declared up at the top so I expected to see that one updated. Thanks!

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад +2

      If you look at the object literal that was assigned to dog, on line 2, it did not have a property called "age".

    • @anitag6925
      @anitag6925 4 года назад +1

      @@SteveGriffith-Prof3ssorSt3v3 I can't believe I missed that. Thank you!

  • @jani.apurva
    @jani.apurva 4 года назад

    Thank you Steve I have learn a lot from your channel keep making videos .....cheers..

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

    Superb❤️

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

    Brilliant tutorials !!!

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

    @6:14 So, would the age data for dog be added if we had used dog.age = 14; instead or would it throw an error because there are 2 dogs in the array?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  Год назад

      If you do EITHER or BOTH of these:
      dog.age = 14;
      dog['age'] = 14;
      Then you will add a property called age to the object dog, if it doesn't exist, or update its value, if it already exists.

  • @CesarJuarezVargas
    @CesarJuarezVargas 7 лет назад

    5:39: Are you adding the label "age" to the variable "cat" or is "age" a variable within a variable? My take is that ir'd be the same as I writing "age":"2" on line 3

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  7 лет назад

      cat and dog are variables that hold objects. Both objects have "properties" called "age".
      There are two ways to get or set the value of the property age.
      1. Square bracket syntax with the property name in quotation marks. objectName["propertyName"]
      2. dot notation - objectName.propertyName
      The square bracket syntax is what you MUST use if you are using a variable to hold the name of the property.

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

    totally amazed

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

    amazing explanation, thanks.

  • @Mohamed-jk8rt
    @Mohamed-jk8rt Год назад

    Thank you a lot :)

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

    How to add a similiar property for the several objects shortly?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  5 лет назад

      That really depends on the context and what you are adding - a method, or a primitive value, or an array. What objects are you adding them to?
      If you just have a couple objects and you want to add a property to each one...
      let obj1 = { };
      let obj2 = { };
      let obj3 = { };
      obj1.prop = 1;
      obj2.prop = 1;
      obj3.prop = 1;
      You work with them each individually.
      If you have a method that you want to add to a lot of objects then you should think about adding that to the prototype for your objects.

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

    Thank you !

  • @CesarJuarezVargas
    @CesarJuarezVargas 7 лет назад

    Is "var" from line 7 the only element that would differentiate an array from adding a new label to an object as in line 16? The latter looks very similar to an array nomenclature in terms of using square brackets.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  7 лет назад

      To create an array, use [ ]
      To create an object, use { }
      arrays use numbers to access their values
      objects use names / labels to access their values.
      BOTH objects and arrays can use the square bracket syntax to target their contents.

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

    Thank you very much,

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

    How can I let more than 1 atribute to property?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  4 года назад

      Sorry. Don't understand your question.

    • @asifahmed6568
      @asifahmed6568 2 года назад

      property has a single word definition ex { name :"User"}, if you want the key to be of two words i.e. User name instead of name you can define like this
      let user= {
      "User name" : "Named user",
      }; and access the property like this ----> console.log(user["User name"]); if i have understood your question correctly then this is what you were looking for

  • @gginnj
    @gginnj 6 лет назад

    How can you add and isolate an object when adding it to an array, so if the elements in the array change, it doesn't change the original object? I tried putting the object in () like "pets=[cat, (dog)]" but that didn't isolate it.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  6 лет назад

      You can't prevent any of the elements from being changed in the array. Any element in an array can be targeted and changed or replaced.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  6 лет назад

      Further, if you changed the object cat or the object dog then the contents of the pets array would now be pointing to the updated version of the objects.

  • @ChrisTian-ox5nr
    @ChrisTian-ox5nr 4 года назад

    Thank YOu!!!

  • @CesarJuarezVargas
    @CesarJuarezVargas 7 лет назад

    Wouldn't it have been the same to add "age":"14" to var dog from the beginning OR being added as dog.age=14?

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  7 лет назад

      Same thing. Just one is happening at the time where the object is being created and the other is happening after the object is created.

  • @juniordallagnolo3983
    @juniordallagnolo3983 7 лет назад

    Hey Steve if I wanted to delete any of my objects properties I would use delete Operator right?
    as is: delete cat.age;
    And how can I save the value in a var before I deleted it? Is this correct? var deleted = delete cat['age'];

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  7 лет назад +3

      The delete operator is how you would remove a property from an Object (if allowed). However, the delete operator does NOT return the value of what it is deleting. It only returns true or false. You would have to put the value into a variable BEFORE calling delete.
      var Obj = { };
      Obj.myprop = 123;
      var temp = Obj.myprop;
      delete Obj.myprop;

  • @jaimedpcaus1
    @jaimedpcaus1 2 года назад

    Cool. Adding objects into an array. How about the opposite? 🙂

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 года назад +1

      let obj = {
      prop: [1, 2, 3, 4, 5]
      }

    • @jaimedpcaus1
      @jaimedpcaus1 2 года назад

      @@SteveGriffith-Prof3ssorSt3v3 I'm either soing something strange, or seeing something strange.
      arr= [1,2,3,4,5];
      let obj ={};
      obj = arr;
      console.log(obj[arr[0]]);
      2
      console.log(obj);
      [ 1, 2, 3, 4, 5 ]

    • @jaimedpcaus1
      @jaimedpcaus1 2 года назад

      Then wrote: console.log(obj[0]);
      1

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  2 года назад

      @@jaimedpcaus1 your third line you are overwriting the object with an array

    • @jaimedpcaus1
      @jaimedpcaus1 2 года назад

      @@SteveGriffith-Prof3ssorSt3v3 meaning it got converted from an object to an array?

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

    You should add these codes on Github.

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

    second round, still amazing.

  • @CesarJuarezVargas
    @CesarJuarezVargas 7 лет назад

    What would be the main difference between using CONSOLE.LOG and DOCUMENT.WRITE? I have come across different positions with regard to those two commands. On one side, DOCUMENT.WRITE not being recommended and on the other side CONSOLE.LOG being used merely as a tool for developers. Then I found RETURN... Here is a CodeAcademy answer, which makes a lot of sense: www.codecademy.com/en/forum_questions/53121d097c82ca0a33003906

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  7 лет назад

      document.write( ) is a way to add new content to the source of an html file WHILE THE HTML FILE IS LOADING. This is NOT recommended. Use the DOM methods to add new HTML to your page after the DOMContentLoaded event has occurred. Document.write( ) does NOTHING after the page has finished loading.
      Console.log( ) is used to write messages to the console. This is for development use only.

    • @CesarJuarezVargas
      @CesarJuarezVargas 7 лет назад

      Which would be a practical application of document.write? If it exists it has to have a usage within our developing work, I would image.

    • @SteveGriffith-Prof3ssorSt3v3
      @SteveGriffith-Prof3ssorSt3v3  7 лет назад

      Cesar Juarez-Vargas 20 years ago it was used. No practical use anymore. Avoid it.

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

    +++