hello,
I have a problem here with myArray.join("");
why the first code work when writing myArray.join("") as a return statement and the second code doesn’t work without being a return statement?
const reverseString = function (string) {
let myArray = string.split("");
myArray.reverse();
return myArray.join("");
};
const reverseString = function (string) {
let myArray = string.split("");
myArray.reverse();
myArray.join("");
return myArray;
};
no i didn’t mean that,
I mean I don’t know which methods mutate the original array and which not.
when I was searching there’s no explination for that join(“”) “only return a new string” not mutate the array.
so I’m asking for a reference which explain which methods change the original array and which only return new thing.
The splice() method changes the contents of an array by removing or replacing existing elements and/or adding new elements in place
So “creates and returns a new string” says nothing about changing the array, while “changes the contents of an array … in place” explicitly says that the array is mutated.
Learning how to read and understand documentation is a skill that takes a fair amount of practice.