Saturday 17 August 2019

How to remove specific element in array in javascript





If I have array, for example :



a=["a","b","c"]  


I need something like



a.remove("a");



How can I do this?


Answer



var newArray = [];
var a=["a","b","c"];
for(var i=0;i if(a[i]!=="a") newArray.push(a[i]);


EDIT: as of newer versions of JS:




var a = ["a","b","c"];
var newArray = a.filter(e => e !== "a");

No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...