在2维数组上强调过滤器操作

时间:2016-05-26 20:17:46

标签: node.js multidimensional-array underscore.js

我有一个代码,想要使用下划线功能过滤值。

var async = require("async");
var test = require('assert');
var _ = require('underscore');
var array = require("array-extended");
test{ var abc = [
[{"key":"469","values":["BALTIMORE CITY           ","BALTIMORE CITY           "]}],
[{"key":"503","values":["BALTIMORE                ","BALTIMORE                "]}],
[{"key":"505","values":["FAIRFAX           "]}],
[{"key":"517","values":["COLUMBIA              ","BELAIR               ","BELAIR               "]}],
[{"key":"534","values":["BETHEL                ","BETHEL                "]}],
[{"key":"471","values":["HAGGERS           ","HAGGERS           "]}],
[{"key":"587","values":["SAN FRANCISCO            ","SAN FRANCISCO          "]}],
[{"key":"551","values":["DALLAS               "]}]];

for (i=0;i<abc.length;i++)
{
    console.log( "results1.key : " +  (abc[i][0].values));
}

console.log( "abc.length : " +  abc.length);

// Filtering only "BETHEL"
var searchstr   = _.filter(abc,function(y){ return _(y.values).some(function(x){return x.trim()=== 'BETHEL';})});
console.log("searchstr.length : "+ searchstr.length);  //returns zero count

for (i=0;i<searchstr.length;i++)
{

    console.log( "results1.key : " +  (searchstr[i].values));
}                       
}

我正在使用的下划线_.filter并没有给我结果。

请有人帮忙。

0 个答案:

没有答案