arrays - javascript operator "in" -


i'm used python, so

a = [1,2,3] 1 in # -> true b = ["1", "2", "3", "x"] "x" in b # -> true 

why in javascript

a = [1,2,3] 1 in // -> true b = ["1", "2", "3", "x"] "x" in b // -> false 

and weirder

"1" in b // -> true 

in works on keys of arrays, not values. 1 in a succeeds because there element #1 in array, 2 value.

"1" fails, because there no 1 property or key in array.

details here: https://developer.mozilla.org/en/javascript/reference/operators/in


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -