0

I'm trying to remove Rohan from this array and return it without the city using splice but I have to call -5 to show the whole array: lotrCitiesArray.splice(-5)

lotrCitiesArray = ["Mordor","Gondor","Rohan","Beleriand","Mirkwood","Dead Marshes","Rhun","Harad"];

results should be ["Mordor","Gondor","Beleriand","Mirkwood","Dead Marshes","Rhun","Harad"];

My code thus far:

function kata8() {
    let newCopy = lotrCitiesArray.slice(0)
    let removeRohan = newCopy.splice(-5)
    let sevElement = document.createElement("div");
    sevElement.textContent = JSON.stringify(removeRohan);
    document.getElementById('kata8').appendChild(sevElement)
    return [removeRohan];
}
flaxel
  • 2,706
  • 4
  • 9
  • 22
  • 2
    Does this answer your question? [How can I remove a specific item from an array?](https://stackoverflow.com/questions/5767325/how-can-i-remove-a-specific-item-from-an-array) – flaxel Sep 13 '20 at 20:35

0 Answers0