I'm attempting to reverse the string "hello" using a For loop, aiming for the output of "olleh". However, I'm facing an issue where the last character in the string is not being removed after being added to the array. Consequently, only the last letter of the string is printed.
What modifications can be made to this code to ensure that the loop eliminates the final character from the string once it has been appended to the array?
function reverseString(str) {
let holder = [];
for (let i = str.length; i > 0; i--) {
holder.push(str.charAt(str.length - 1));
str.slice(0, -1);
}
return holder;
}
console.log(reverseString("hello"));