M
mouac01
I have this multi-dimensional array:
var list = [["a","1"],["a","2"],["b","1"],["b","2"]]
I need a filter function that I can pass the search index and value:
list.filter(0,"a") returns [["a","1"],["a","2"]]
and
list.filter(1,"1") returns [["a","1"],["b","1"]]
-----------
The only thing I found is the filter function below but I'm not sure
how to implement it for multi-dimensional arrays. Thanks....
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/) {
var len = this.length;
if (typeof fun != "function") throw new TypeError();
var res = new Array();
var thisp = arguments[1];
for (var i=0;i<len;i++) {
if (i in this) {
var val = this;
if (fun.call(thisp, val, i, this)) res.push(val);
}
}
return res;
}
}
var list = [["a","1"],["a","2"],["b","1"],["b","2"]]
I need a filter function that I can pass the search index and value:
list.filter(0,"a") returns [["a","1"],["a","2"]]
and
list.filter(1,"1") returns [["a","1"],["b","1"]]
-----------
The only thing I found is the filter function below but I'm not sure
how to implement it for multi-dimensional arrays. Thanks....
if (!Array.prototype.filter) {
Array.prototype.filter = function(fun /*, thisp*/) {
var len = this.length;
if (typeof fun != "function") throw new TypeError();
var res = new Array();
var thisp = arguments[1];
for (var i=0;i<len;i++) {
if (i in this) {
var val = this;
if (fun.call(thisp, val, i, this)) res.push(val);
}
}
return res;
}
}