Basic Algorithm Scripting - Mutations

I couldn’t figure out why the following codes can’t convert newArr to lowercase. Does anyone have a clue?

It’s from the challenge on https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/basic-algorithm-scripting/mutations

function mutation(arr) {
  
  let newArr = arr.slice();
  for(let i = 0; i < newArr.length; i++){
    newArr[i].toLowerCase();
    console.log(newArr[i].toLowerCase()) // log hello hello
    console.log(newArr) // still log [ 'hello', 'Hello' ]
  
  }
}

mutation(["hello", "Hello"]);

Thanks for reading!

For your code to change an array element to lower case you would need:

newArr[i] = newArr[i].toLowerCase();

@igorgetmeabrain Thank you!!

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