JS Tutorial: Find if Two Object Values are Equal to Each Other

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

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

  • @qone2363
    @qone2363 Год назад +3

    Hi! As the tutorial went on, I have noticed that "//?" in vscode led to an "shortcut" output. Can you let me know which extension this is? Also, is this available on replit?

  • @dcernach
    @dcernach 6 лет назад +10

    Another amazing video... Great explanation and exemplification... You totally deserve more subscribers... Just a quick question, what is the plugin which are you using to execute conde inline with "//?"...

    • @edutechional
      @edutechional  6 лет назад +5

      I'm glad that you found it helpful! And it's the Quokka JS extension, I show how to use it in this video: ruclips.net/video/1ABsTHKchLY/видео.html

  • @JeanMarcSaintLaurent
    @JeanMarcSaintLaurent 4 года назад +4

    Sweet can of corn! Finally someone who answered my question!

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

    but if the objects are inside on the array.
    var hunterco = [{
    candidato: "Anderson",
    evento: "REPROVADO",
    }, {
    candidato: "Anderson",
    evento: "REPROVADO"
    }
    ]

  • @PaulaSanchez31
    @PaulaSanchez31 3 года назад +1

    Thanks Jordan, always so kind.

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

    @edutechinal
    May I ask how you get direct return values in the code editor?
    Thinking.. line 17: isEqual(obj1, obj2) .. your blue text changes as you write code.

  • @solo-angel
    @solo-angel 5 лет назад

    Awesome, thank you very much!
    I've purchased two Ruby courses from you as well and am very happy!

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

      I'm glad that you are enjoying them, thanks!

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

    is the lodash function using the recursion internally? Cannot think of a different implementation

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

    Great explanation and on the point. Thank you.

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

    Surely this'll fail if obj1 & obj2 have the same number of keys but one of obj1's keys return `undefined` (&, perhaps, if one of obj2's (differently-named) keys return `undefined`). For example, obj1 has `color: undefined` & obj2 has `shape: undefined`. `obj1.color`'ll return `undefined` but so will `obj2.shape`. `obj2.shape`'ll return `undefined` but so will `obj1.color`. It's an edge-case but could still catch people out.

  • @AndersonSilvaMMA
    @AndersonSilvaMMA 6 лет назад +3

    Isn't better to just JSON.stringify() both objects and compare the strings?

    • @edutechional
      @edutechional  6 лет назад +4

      Absolutely, you can do that as well. One of the purposes of this guide was to show a tricky part of JS that a number of my students have run into.

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

      Cool! But which one you recommend? In my humble opinion, the JSON.stringify is much faster :)

    • @edutechional
      @edutechional  6 лет назад +1

      To me it depends on the situation. Stringify is easier to remember, so it might be the best option in a coding interview, but if you're building an application in a tool such as React, or Vue, it's recommended to use tools such as pure components.

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

      Thanks! :)

    • @ralexand56
      @ralexand56 5 лет назад +3

      The problem though is this only works if the keys are in the same position for both objects which might not be the case for alot of problems for example if you create an object to store value counts.

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

    2021 and this is super useful

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

    this video is highly educational...Thank you

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

    In my case I have nested object. I have to check equals without using library. Please help me out on this one

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

      You can convert the full object (or nested element) into a string using JSON.stringify and then then compare it that way.

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

    are you using a free version of Quokka JS? That functionality really helps see your output

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

      I'm using the paid version, but the free version has quite a bit of functionality as well!

  • @amjad-se
    @amjad-se 4 года назад +1

    Thanks for the great video. I figured out how to do deep comparison of objects using recursion.
    const isEqual = function(obj1, obj2) {
    const obj1Keys = Object.keys(obj1);
    const obj2Keys = Object.keys(obj2);
    if(obj1Keys.length !== obj2Keys.length) {
    return false;
    }
    for (let objKey of obj1Keys) {
    if (obj1[objKey] !== obj2[objKey]) {
    if(typeof obj1[objKey] == "object" && typeof obj2[objKey] == "object") {
    if(!this.isEqual(obj1[objKey], obj2[objKey])) {
    return false;
    }
    }
    else {
    return false;
    }
    }
    }
    return true;
    };
    Hope this helps!

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

      Thanks for sharing!

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

      can you explain how line work >> !this.isEqual(obj1[objKey], obj2[objKey])) how this "this" come , and how works

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

    What IDE are you using? Looks super clean

  • @AbidAli-jq9kn
    @AbidAli-jq9kn 3 года назад

    which extension are you using for getting the result in vsCode?

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

    thank you man i love this video

  • @RajaSekar-rf9xf
    @RajaSekar-rf9xf 8 месяцев назад

    how to compare two json have the same properties without order? let obj1 = { name: "person 1",age:5}; let obj2 = {age:5, name: "person 1"};

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

    Great explanation!

  • @fireabtesfaye1369
    @fireabtesfaye1369 10 месяцев назад

    what if is use
    function isEqueal(a: object, b: object) {
    return JSON.stringify(a) === JSON.stringify(b);
    }

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

    Awesome, thank you very much!

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

    Crystal Clear.

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

    Is it possible to compare two different objects, then set all the values in the longer one, equal to the shorter one (while keeping the other ones as they are)?
    So for example:
    var obj1 = {
    name: "Bob",
    age: 18,
    pet: "cat"
    }
    var obj2 = {
    name: "Kristine"
    age: 13
    }
    and then make
    obj1 = {
    name: "Kristine",
    age: 13,
    pet: "cat"
    }

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

      imgur.com/a/ON0gti2
      I think I figured it out lol

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

      Yes, for something like that you can compare the object keys and then add the key(s) that are different: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/keys

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

    What is he using to debug?

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

    I create a function airplane (model, seatingCapacity,maxSpeed){
    this.model=model;
    this.seatingCapacity=seatingCapacity;
    this.maxSpeed=maxSpeed;
    }
    Var obj = new airplane ("A 7745", 150,450);
    I want increase value seatingCapacity by object 10
    And delete maxSpeed for all object
    And add new property average speed for all object with value 600

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

    Great!

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

    if(JSON.stringify(obj1) == JSON.stringify(obj1)){
    return true
    }return false
    OVER !

    • @pkSays
      @pkSays 2 месяца назад

      this fails when order of key is different