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.
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.
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));