Skip to content
← Back to Community
How to remove item from list
Profile icon
MatthewX

How do you remove a item from a list in js? Like a = "somenumberinlist" and then remove a from the list.

Voters
Profile icon
MatthewX
Comments
hotnewtop
Profile icon
PattanAhmed

@MatthewX Hi,
I think this website might help you:-
Click here
Thanks!

Hope this helps

Profile icon
Coder100

for you:

let array = [1, 2]; array.splice(0, 1); // delete first item
Profile icon
JoannaRolluque

@Coder100 what about in Python 3?

Profile icon
Coder100

Array.splice(index, deleteamount)
read more

Profile icon
MatthewX

@Coder100 but i dont want to delete a certain position

Profile icon
MatthewX

@Coder100 i just want to delete a random item from the list

Profile icon
Coder100

@MatthewX oh, well you can generate one

Profile icon
MatthewX

@Coder100 wdym?

Profile icon
Coder100

@MatthewX

function generate(arr) { return arr[Math.floor(Math.random() * arr.length)] } arr.splice(generate(arr), 1)
Profile icon
MatthewX

@Coder100 i meant like delete an item without using position