-1

I have an array in javascript.Example

var array=[1,2,3,4,5,2,6,7,2];

Ok, i want to delete value 2 in array. The result as

var array=[1,3,4,5,6,7];

Thank guys.

1
  • 1
    Look at splice and indexOf()... if you can create a new array then look at filter() Commented Sep 28, 2015 at 7:50

1 Answer 1

1

Use filter() for that

var array = [1, 2, 3, 4, 5, 2, 6, 7, 2];

array = array.filter(function(v) {
  return v != 2
});

console.log(array);

Sign up to request clarification or add additional context in comments.

2 Comments

@ArunPJohny : updated , jsfiddle.net/w5LeyLuh/2

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.