【发布时间】:2017-03-01 14:56:31
【问题描述】:
所以我有一个包含两个不同数组的数组:
var _staticRoutingTable = [];
function StaticRoute(directory, extentions) {
this.dir = directory;
this.extentions = extentions;
}
_staticRoutingTable.push(new StaticRoute(["htmlfolder"], ["./html"]));
_staticRoutingTable.push(new StaticRoute(["somefolder"], ["./html","./txt","./css"]));
假设我只想获取文件夹名称为“somefolder”的“dir”数组。
所以我不想这样,因为...:
return _staticRoutingTable.forEach(function callb(route) {
return route.dir.filter(function callb(directory) {directory=="somefolder" })
});
.... 我得到 dir + 扩展数组。我怎样才能只过滤一个数组(在本例中为“dir”)。
【问题讨论】:
-
所以你想要完整的 StaticRoute,它有 this.dir == 'somefolder' ?
-
@baao 不,我不希望StaticRoute完整,我只想返回一个数组,其中包含一个名为“somefolder”的字符串(在本例中9