Assessment wanted for Arrays 2 skill test


The above is the code for my assessment.
I need space between individual items of the array,So how to make it possible?
Thank you.

Hi @vaishnavi_A.N

For this task it’s enough to do const myArray = myString.split('+');. This code splits the string at every plus sign and puts the elements into the array.

Not part of this task, but If you would like to have spaces after the commas you could join the array to a string again like this: const newString = myArray.join(', ');

I hope that helps,
Michael

Thank you @mikoMK,But when I put the above statement in my code, I get the last item in the array as the entire array.
I have experimented that while I use quotes without gap, the array splits into each letter and if i give a space between the quotes, it gives me the desired result.
Can u please help me in noting the difference between myString.split(’+’) and myString.split(’ ');

1 Like

You need to replace the second and third line with my code above.
This would be a working solution for this task:

const myString = 'Ryu+Ken+Chun-Li+Cammy+Guile+Sakura+Sagat+Juri';
const myArray = myString.split('+');
const arrayLength = myArray.length;
const lastItem = myArray[arrayLength - 1];
1 Like

Yes it worked perfect, thank u so much @mikoMK. :+1: :+1:

1 Like