#Why are two identical string resulting in a *false* when I compare them????

3 messages · Page 1 of 1 (latest)

harsh swallow
#

This is the exact text that was logged to the console:

window0E9DA0 windowBF8DF2 FreshWindow.js:94
false FreshWindow.js:95
window92FD5D windowBF8DF2 FreshWindow.js:94
false FreshWindow.js:95
windowBC45CA windowBF8DF2 FreshWindow.js:94
false FreshWindow.js:95
window7FDB32 windowBF8DF2 FreshWindow.js:94
false FreshWindow.js:95
windowBF8DF2 windowBF8DF2 FreshWindow.js:94
false FreshWindow.js:95
-1 FreshWindow.js:100
Array(5) [ div#windowBF8DF2.window, div#window0E9DA0.window, div#window92FD5D.window, div#windowBC45CA.window, div#window7FDB32.window
 ]
FreshWindow.js:101
#

Heres the expanded array:

Array(5) [ div#windowBF8DF2.window, div#window0E9DA0.window, div#window92FD5D.window, div#windowBC45CA.window, div#window7FDB32.window
 ]
​
0: <div id="windowBF8DF2" class="window">​
1: <div id="window0E9DA0" class="window">​
2: <div id="window92FD5D" class="window">​
3: <div id="windowBC45CA" class="window">​
4: <div id="window7FDB32" class="window">
​
length: 5
silver condor
#
console.log((arr[i].id).trim() + " " + (id).trim)
console.log(arr[i] === id)

The items logged are not the items compared. The first log trims while the comparison is between untrimmed items. Also the comparison is still not equivalent if we ignore the trimming. The first output uses arr[i].id while the comparison uses arr[i] without selecting the id property. If id is a string and the array holds objects, they cannot be equal unless you deliberately override how the object is coerced to primitive, which is neither necessary nor common.

Also, I just noticed that the second trim is not correct, because it is missing parentheses.