Get value of selected LI and remove it from array

I have a list of user inputted strings, and want to be able to delete one individual item, while also removing it from the array. I am able to remove it successfully from the DOM, but not from the array.

So far I have tried to get the value of the selected LI and select the indexof that specific LI

$(document).on('click', 'button.delete', function () {
    let deletedItem = $(this).closest('li')
    let itemValue = $(this).closest('li').val()
    let index = items.indexOf(itemValue);
    if(index != -1) {
        items.splice(index, 1);

This does not delete it from my array, any ideas how it would be done?

20 thoughts on “Get value of selected LI and remove it from array”

  1. 655624 587275Hi there, just became alert to your weblog via Google, and located that its truly informative. Im gonna watch out for brussels. Ill be grateful in the event you continue this in future. Lots of individuals will likely be benefited from your writing. Cheers! 474513

  2. 314192 488267Thank you for the auspicious writeup. It in reality was a amusement account it. Appear complicated to far delivered agreeable from you! However, how can we maintain in touch? 755532

  3. The way you put together the information on your posts is commendable. I would highly recommend this site to those looking for some great resources about Transportation Industry. You might also want to check my page for some noteworthy inputs.


Leave a Comment