Hello World! As the title says, I have an array and converted it with toString() however when I check the console.log using typeof, I get an object, meaning it’s still an array. Could someone point out what I’m doing wrong? Thank you.
Your code so far
function reverseString(str) {
let strArray = ((str.split("")).reverse());
console.log (strArray.toString());
console.log (typeof strArray);
}
reverseString("hello");
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Safari/537.36.
well, toString() doesn’t change the thing it ws used on, but creates a new string
so if you do let str = strArray.toString() it will work. Anyway, you may want to not use that, as you will find yourself with a string of value e,l,l,o,h. Maybe check out the join() method instead
Thanks for your quick reply! I originally used join() but since the answer wasnt accepted I thought it still wasnt converted to a string. I see where I’m wrong now, thanks for your help!