HELP plz understanding JavaScript issue

 const list = document.querySelector('.output ul');
list.innerHTML = '';
let stations = ['MAN675847583748sjt567654;Manchester Piccadilly',
                'LIV5hg65hd737456236dch46dg4;Liverpool Lime Street',

for (let i = 0; i < stations.length; i++) {
  let input = stations[i];
  let code = input.slice(0,3);
  let semiC = input.indexOf(';');
  let name = input.slice(semiC + 1); //This line!
  let result = code + ': ' + name;
  let listItem = document.createElement('li');
  listItem.textContent = result;

can u tell me what is that +1 for inside the name variable?

Hello @code-hunter

slice here will take copy of the string from start till the index of the ; but since slice use exclusive way that it does not take the last index so they add 1 so it include that ;

check this one to get more about slice

hope that help and have a nice day :slight_smile:

1 Like

Hey, Thank you so much! never knew i could do that.

you very welcome :slight_smile:

1 Like