2021-12-25

Removing a specific string from an array

else if(input === 'remove'){
    let search = prompt('what index do you want to remove');
    for(let j=0;j<todos.length;j++){
        console.log(`current data is:${todos[j]}`);
        if(todos[j] === search){
            console.log(`data to be delete is present`)
            todos.splice(todos[j],1);
            console.log(`data deleted is ${todos[j]}`)
        }
    }

if todos contains [task1, abc, def]

my output is :

current data is:task1

current data is:abc

current data is:def

data to be delete is present

data deleted is undefined

How do I remove the element that is todos[j] from the list todos[]



from Recent Questions - Stack Overflow https://ift.tt/3H7NCHh
https://ift.tt/eA8V8J

No comments:

Post a Comment