DEV Community

Discussion on: Demystifying Array.prototype.flat

Collapse
 
karataev profile image
Eugene Karataev

I'm nitpicking here, but

arr.flat(1) === arr.flat()

is false.

flat returns a new array and since objects (arrays) are compared by reference, any comparison of two arrays located in different memory slots will always return false.

Collapse
 
laurieontech profile image
Laurie • Edited

Thanks for catching that.
That was me throwing it in really quick when someone asked me to make that distinction clear. Shouldn't have used code highlighting/syntax to explain it. I'll adjust!