How to remove a specific value from a javascript array

Here is a simple trick to remove a particular value from your array:

// from this (6 items)
var arr = ['remove', 'specific', 'value', 'from', 'javascript', 'array']; 

// to this ("specific" value removed)
var arr = ['remove', 'value', 'from', 'javascript', 'array']; 

// use this (removes "specific")
arr.splice(arr.indexOf('specific'), 1);

// full example
var arr = ['remove', 'specific', 'value', 'from', 'javascript', 'array'];
var value_to_remove = 'specific';
arr.splice(arr.indexOf(value_to_remove), 1);
Tags: ,

Leave a Reply

Your email address will not be published. Required fields are marked *

*
*