****我有一个包含其他数组的数组,如下所示,我的目的是在其中找到在其中的第3个位置包含字符串Type 4 Sheets的数组。一般来说,如果我只能在较大的数组中获得那些包含第n个位置的特定字符串的数组,那将真的很棒。
[[sheets at upper, intermediate and lower, Type 4 Sheets, Sheets, 8.0, 1.5, 5.0, , 3.0, Exact Sized Material # 1],
[sheets at back , Type 4 Sheets, Sheets, 8.0, 1.0, 2.5, , 1.0, Exact Sized Material # 2],
[dfsdfdsfsd, Type 2 Gola, Gola, 5.0, 1.5, 2.5, , 2.0, Exact Sized Material # 3],
[sheets at vertical divider, Type 1 Gola, Gola, , 1.5, 2.5, , 1.0, Exact Sized Material # 4],
[sheets at shutters, , , 2.0, , 2.5, , 4.0, Exact Sized Material # 5],
[sheets at shutters, , , 8.0, , , , 12.0, Exact Sized Material # 6],
[sheets at shutters, , , 8.0, , , , 8.0, Exact Sized Material # 7],
[sheets at shutters, , , 2.5, , , , 8.0, Exact Sized Material # 8],
[sheets at shutters, , , 1.5, , , , 8.0, Exact Sized Material # 9],
[sheets at shutters, , , 2.5, , , , 8.0, Exact Sized Material # 10],
[sheets at shutters, , , 2.5, , , , 4.0, Exact Sized Material # 11],
[sheets at shutters, , , 2.0, , , , 32.0, Exact Sized Material # 12],
[sheets at shutters, , , 2.5, , , , 32.0, Exact Sized Material # 13]]
答案 0 :(得分:1)
看看是否有帮助
arr.filter(x => x[positionToCheck] === stringToCheck)
根据此处的评论为转译版本
arr.filter(function (x) {
return x[positionToCheck] === stringToCheck;
});
答案 1 :(得分:0)
这可以通过使用SELECT i.number, i.description,
MAX(CASE WHEN am.attribute_code = 'brand' then am.attribute_value END) as brand,
MAX(CASE WHEN am.attribute_code = 'model' then am.attribute_value END) as model,
MAX(CASE WHEN am.attribute_code = 'category' then am.attribute_value END) as category,
MAX(CASE WHEN am.attribute_code = 'subcategory' then am.attribute_value END) as subcategory
FROM items i JOIN
attr_maps am
ON am.number = i.number
WHERE i.number = AB123
GROUP BY i.number, i.description
在javascript中完成:
forEach
results = [];
outerarray.forEach(function(a) {
if (a[2]==="Type 4 Sheets")
results.push(a)
});
将是a
outerarray
应该具有所有内部数组,这些数组在第3个包含给定的字符串。位置。