This is the question
For this final array task, we provide you with a starting array, and you will work in somewhat the opposite direction. You need to:
- Remove the last item in the array.
- Add two new names to the end of the array.
- 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. - Finally, join the array items together in a single string called
myString
, with a separator of "-
".
My Code:
let myArray = [ “Ryu”, “Ken”, “Chun-Li”, “Cammy”, “Guile”, “Sakura”, “Sagat”, “Juri” ];
myArray.pop();
myArray.push(‘Alexander’, ‘Rengkat’);
for(var i=0;i<myArray.length;i++){
myArray[i] = myArray[i]+’ ‘+’(’+i+’)’;
}
let myString;
myString = myArray.join(’ - ');
//And the Output I get is:
Ryu (0) - Ken (1) - Chun-Li (2) - Cammy (3) - Guile (4) - Sakura (5) - Sagat (6) - Alexander (7) - Rengkat (8)
Please see my code and tell me whether I’m correct. Is this the required output.
Thanks in Advance!!!