Basic Algorithm Scripting - Mutations

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 to loop through the keys in an object. But you have strings, not objects. You can instead make comparisons using the strict equality operator ===.

"h" === "h" // true
"h" === "e" // false
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.