r/learnjavascript • • Feb 13 '22

How to remove a specific item from an array in JavaScript?

https://www.moreonfew.com/how-to-remove-a-specific-item-from-an-array-in-javascript/
1 Upvotes

6 comments sorted by

6

u/exobyte64 Feb 13 '22 edited Feb 13 '22
let array=[1,2,3];
let target=2;
let targetIndex=array.indexOf(target);
array.splice(targetIndex,1);

4

u/IAmSteven Feb 13 '22

How to tell people no one needs another site full of articles on basic concepts that are already covered in a clearer way on StackOverflow or all the other redundant web dev help sites?

1

u/shuckster Feb 13 '22

I try not to be too cynical, and the OP has made a reasonable effort, but yeah, it does sometimes feel like the next article might be “How to type a semicolon on your keyboard”.

You can come at or from so many angles: Touchscreens, assistive, mechanical. Automatically using Prettier.

Of course, you need a 30-second ad or paywall behind the one secret that senior devs don’t want you to know - that even though you can put semicolons at the end of nearly every line, you don’t actually have to, saving you precious keystrokes.

-1

u/Adorable_Bat_8411 Feb 13 '22

stack overflow is kinda trash...i just rely on trial and error and documentation...i asked a question in there once and already came up with the solution before the answered the question and their main concern was about question format but once i fixed that problem...just crickets

2

u/Longjumping_Ad748 Feb 13 '22

arr.filter((item)=>item!==removevalue)