I wish to use splice on string e.g.
console.log(removeFromString('Elie', 2, 2)) // 'El'
If you really want to use splice(), you can spread the string to an array, invoke splice() on the array, and join() the results back together:
const removeFromString = (s, x, y) => {
const array = [...s];
array.splice(x, y);
return array.join('');
}
console.log(removeFromString('Elie', 2, 2));
I think this is what you want to do.
function removeFromString(string, start, count) {
let str = string.split('');
str.splice(start, count);
return str.join('');
}
console.log(removeFromString('Elie', 2, 2));
Try this:
function removeFromString(str, start, end) {
let arr = Array.from(str);
arr.splice(start, end);
return arr.join(String());
}
and then use:
removeFromString('Elie', 2, 2);