/* Here’s my code: */
const newOb = {
name: 'bob',
field: 'spelunking,
id: '34054'
}
const newAr = [ 'name', 'field', 'id' ]
Object.keys(newOb) === newAr
/* it returns false. Why? */
/* Here’s my code: */
const newOb = {
name: 'bob',
field: 'spelunking,
id: '34054'
}
const newAr = [ 'name', 'field', 'id' ]
Object.keys(newOb) === newAr
/* it returns false. Why? */
You can’t compare the contents of two arrays with the equality operator. The array created by Object.keys
is a different object than the array newAr
, so it is false.
Wait. So the array created by Object.keys is an object? Is it both an array and an object?
All arrays are objects.
Ok. So if you were to compare any two arrays with === it would return false. I see.
Thanks!