0

class MyClass {
  returnSame(arr){
    return arr;
  }
}

var myClass = new MyClass();
console.log( [1] == myClass.returnSame([1]) );

I'm expecting the log to be true, but it's false. I'm sure this has to do with some fundamental principle of JavaScript that has managed to pass me by.

Why is this not true?

jackreichert
  • 1,979
  • 2
  • 23
  • 36
  • 2
    you'll see the same behavior with `[1] === [1]`. in other words, this has nothing to do with ecmascript-6 – jeremy Aug 14 '16 at 20:24
  • Thanks, of course. I should have known that one. With double, it still returns false though. – jackreichert Aug 14 '16 at 20:27
  • 1
    It doesn't matter if it's double or triple. `[] !== []` and `[] != []` and `({} != {})` and so on. – Oriol Aug 14 '16 at 20:31
  • I understand, so you're saying that there is no straight way to compare arrays without iteration. This looks like what I'm looking for. http://stackoverflow.com/questions/7837456/how-to-compare-arrays-in-javascript Thanks for your help. – jackreichert Aug 14 '16 at 20:36
  • 1
    if the array values are primitive, and you don't care about sparseness, you can compare them as Strings. – dandavis Aug 14 '16 at 20:47

0 Answers0