JavaScript Problem: Checking if 2 Objects have the Same Data

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

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

  • @mrcaf2824
    @mrcaf2824 2 года назад +1

    Thank you sir. Great video. I had assumed making the object an object array the array high functions would work correctly on them. But the key was to literally to call Object.keys on the object to access it keys then properties. Thank you again.

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

    Great tutorial, thanks. Im curious what the code would look like when the values are indeed objects or arrays.

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

      Do you mean what I showed at the start when I cycled through the array normally or I you referring to something else?

  • @sofilove...20
    @sofilove...20 2 года назад

    Your English sounds so clear & also thanks for your solutions...:)(:

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

    I love your tutorials. Keep up the good work

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

    You can check if the content of each key is an object or an array or a simple value. Then use recursion approach

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

    what about JSON.stringify(obj1) === JSON.stringify(obj2) ?

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

      Love it!! Great suggestion!

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

      @@AllThingsJavaScript this is a deep compare vs shallow one in the video. correct?

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

      @@ortania Yes, this would work as a deep compare.

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

    Hope one day you will make just a simple app with JS (like a todo list) .

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

    What about each using JSON stringify to check if the string equivalents of the objects are equal? I tried it, and it seems to work. The syntax is also much easier. Is there a disadvantage to using this or some gotcha that I am not considering? Are there any plans to add a method in JS to make deep clones of objects or to check for object equality?

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

      Yes, great idea with JSON.stringify. The only gotcha I can think of is with sub objects. Some issue that comes up with deep cloning.

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

    What about checking the other direction hasSameDataObh(obj2, obj1). ? Maybe obj2 has more properties than obj1

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

      he did check the length of the objects to be the same, so it can't have more properties

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

      @@GodsDevil5thF Thanks forgot it

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

    Stringify is the best solution

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

    Thanks for the video, I have a question? what if the objects have nested object then we need to loop through it?

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

      Yes, that becomes much more complicated. YOu would need to loop through those. Perhaps that would be a good follow up tutorial.

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

    How to compare array of json objects irrespective of its order

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

      Can you provide an example of what you are trying to do?

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

      @@AllThingsJavaScript just re-order the elements in obj2...

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

    I have array inside the object . And I have to check the same data . Please upload video on it . Thanks in advance. Please reply

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

    Please modify this function. It will really works for me