following the snippet bellow, why an array with one position is not working properly when using IN
operation?
You can see that with 2 item the operation works fine.
- Why this is happening?
- What's the work around?
// helper function
function showResult(result) {
document.querySelector('#result').innerHTML += result+'<br/>';
}
var a = ["1"]
var b = "1"
showResult(b in a);
//false
var a = ["1","2"]
var b = "1"
showResult(b in a);
//true
<div id="result"></div>