Javascript comparing array

Hello there ! :slight_smile:

Someone can tell me why this is false

const ab = ["a","b"]

const ba = ["a","b"]

console.log(ab === ba)

two object instances will never be equal. you sould use, first a comparison of length and after that go throug each element i compare them.

1 Like

Thanks you sir for fast answer

but you can compare it like that :slight_smile:
if(JSON.stringify(ab)==JSON.stringify(ba)).

If you want to learn how the compile of js does things i recomend thoses book:

font : https://www.geeksforgeeks.org/how-to-compare-two-arrays-in-javascript/

1 Like

:o Amazing ! Thanks for sharing :slight_smile: