0

[{"email":"akhiltrivedi@outlook.com","pass":"akhil@1","name":"akhil","car1":"zen","year1":"2012","member":"no","mobile":"(903) 309-8713"},{"email":"anandpatel@gmail.com","pass":"Smith@1","name":"suresh","car1":"zen","year1":"2012","member":"yes","mobile":"(903) 309-8799"},{"email":"contact@akhiltrivedi.com","pass@1":"akhil@1","name":"rakesh","car1":"zen","year1":"2012","member":"no","mobile":"(903) 309-2233"},{"name":"akhil","email":"akhiltrivedi@outlook.india","pass":"akhil@123","mobile":"(903) 309-8713","car1":"zen","car2":"","year1":"2012","year2":"","member":"yes"},{"name":"karan","email":"contact@akhiltrivedi.com","pass":"akhil@123","mobile":"(903) 309-2233","car1":"zen","car2":"","year1":"2012","year2":"","member":"yes"}]

This is my array and i wan to delete array containing email id = akhiltrivedi@outlook.com so, how can i delete it ?

Akhil
  • 159
  • 1
  • 11

1 Answers1

0

I suggest to use Array#filter() and assign the result to the wanted variable.

var array = [{ "email": "akhiltrivedi@outlook.com", "pass": "akhil@1", "name": "akhil", "car1": "zen", "year1": "2012", "member": "no", "mobile": "(903) 309-8713" }, { "email": "anandpatel@gmail.com", "pass": "Smith@1", "name": "suresh", "car1": "zen", "year1": "2012", "member": "yes", "mobile": "(903) 309-8799" }, { "email": "contact@akhiltrivedi.com", "pass@1": "akhil@1", "name": "rakesh", "car1": "zen", "year1": "2012", "member": "no", "mobile": "(903) 309-2233" }, { "name": "akhil", "email": "akhiltrivedi@outlook.india", "pass": "akhil@123", "mobile": "(903) 309-8713", "car1": "zen", "car2": "", "year1": "2012", "year2": "", "member": "yes" }, { "name": "karan", "email": "contact@akhiltrivedi.com", "pass": "akhil@123", "mobile": "(903) 309-2233", "car1": "zen", "car2": "", "year1": "2012", "year2": "", "member": "yes" }];

array = array.filter(function (a) {
    return a.email !== 'akhiltrivedi@outlook.com';
});

document.write('<pre>' + JSON.stringify(array, 0, 4) + '</pre>');
Nina Scholz
  • 323,592
  • 20
  • 270
  • 324