Tell us what’s happening: hey guys , i want to know why i can’t use “… in …” in this case.
**Your code so far**
function mutation(arr) { let taille=arr[1].length; for(let i=0; i<=taille;i++){ if(arr[1][i] in arr[0]){ } } } mutation(["hello", "hey"]);
Here’s the error:
Uncaught TypeError: cannot use ‘in’ operator to search for “h” in “hello”
You use for...in to loop through the keys in an object. But you have strings, not objects. You can instead make comparisons using the strict equality operator ===.
for...in
===
"h" === "h" // true "h" === "e" // false
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.