Reputation: 49
I have an issue where i want to add a char at a specific index in a string. Its supposed to take a http... address and add "s" at the end of http. After splice console log doesn't even print "url". What am I doing wrong?
const url = hero.comics.collectionURI.split("").splice(5, 0, "s").join("");
Upvotes: 2
Views: 576
Reputation: 89294
splice
returns the deleted elements as an array, not the array it was called on.
let arr = hero.comics.collectionURI.split("");
arr.splice(5, 0, "s");
const url = arr.join("");
Upvotes: 2