array's filter
var arr = [ { id: 15 }, { id: -1 }, { id: 0 }, { id: 3 }, { id: 12.2 }, { }, { id: null }, { id: NaN }, { id: 'undefined' } ]; var invalidEntries = 0; function filterByID(obj) { if (obj.id !== undefined && typeof(obj.id) === 'number' && !isNaN(obj.id)) { return true; } else { invalidEntries++; return false; } } var arrByID = arr.filter(filterByID); console.log('Filtered Array\n', arrByID);
-----------------------------------------------------------------------小二给我来二两轮子!