Hello everyone. I’m working on Arrays 3, and I’m stuck on the third exercise:
Go over each item in the array and add its index number after the name inside parentheses, for example Ryu (0) . Note that we don’t teach how to do this in the Arrays article, so you’ll have to do some research.
My approach has been to loop over the array, and add the parenthesis besides each item in the array.
How can I find the index of each item in the array, and then loop over my array so as to add the index number besides each name.
Also, how can I put the index number for each item inside a parenthesis, and then add that to the Array.
I tried various things, including indexOf but that will only return the index of a specific item you are searching for, what if the array contains hundreds of items? I essentially want to find the final index, then starting at 0, loop over the array and add (i), incrementing by 1 each time until I reach the final item in the array.
Let me know if anything is unclear or if you have any questions! Thank you in advance.
One thing — I did have to add backticks round the template literal inside the for loop, as the code wasn’t working for me, but then I realised that Discourse had eaten them
In future, please consider putting your code into an online code editor like codepen, and then sharing the URL with us — this makes it much easier to test and debug, and it also avoids such problems.
you doing great well done you just need to add extra space between the index number and the element
so it will be myArray[i] += ` (${[i]})` ;
and it better in your future post to create a new post and put your code in any online service and share link to that in the post with link to the task or topic you asking about