0

lets take a word = bird I want output =

ibrd

I should change its position to the beginning. can I do this using JavaScript? how can I do this using string.

  • Do this resolve it? https://stackoverflow.com/questions/5306680/move-an-array-element-from-one-array-position-to-another – mateonunez Oct 14 '20 at 10:25

1 Answers1

0

I think this will solve your problem

const changeLetter = (val /* string value */, index /* index of the letter (i in this scenario)*/) => {
  let temp = val.split('');

  temp.splice(index, 1);
  temp.unshift(val[index]);

  return temp.join('');
}

const val = 'bird';

console.log(changeLetter(val, 1));
firatozcevahir
  • 892
  • 4
  • 13