For an array: [\"5\",\"something\",\"\",\"83\",\"text\",\"\"]
[\"5\",\"something\",\"\",\"83\",\"text\",\"\"]
How to remove all non-numeric and empty values from an array? Desired output: [\"5\"
[\"5\"
Use array.filter() and a callback function that checks if a value is numeric:
var arr2 = arr.filter(function(el) { return el.length && el==+el; // more comprehensive: return !isNaN(parseFloat(el)) && isFinite(el); });
array.filter has a polyfill for older browsers like IE8.