JSFiddle - React, Tailwind, and code Playground
by yangchenyun
JavaScript
Array.prototype.filter = Array.prototype.filter || function _filter( fnc /*, thisv */ ) {
if( this === undefined || this === null ) {
throw new TypeError('Array.prototype.filter');
}
var t = this instanceof Object ? this : new Object( this ),
len = t.length >>> 0,
res = [ ],
i = 0,
thisv = arguments[ 1 ],
stored = null;
if( typeof fnc !== 'function' ) {
throw new TypeError('Array.prototype.filter');
}
for(i = 0; i < len; i++) {
if( i in t ) {
stored = t[i];
if( fnc.call(thisv, stored, i, t) ) {
res.push(stored);
}
}
}
return res;
};
object = {};
object.items = [[null, null], [1, '3'], [2, '3']];
var filtered = object.items.filter(function(item) {
if (typeof item === undefined || $.isEmptyObject(item) || item === null) {
return false;
} else {
if (typeof item[1] === undefined || $.isEmptyObject(item[1]) || item[1] === null) {
return false;
}
else {
return true;
}
}
});
alert(filtered);