我有 JSON 数据数组
[
{
_id: 5f2084f656dc2428e96fbe92,
category: [ '5e5150c6c52a3904b74d6ff7', null ],
coordinates: { lat: 37.8025909, lng: -122.4336412 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3323.833296768243
},
{
_id: 5f2084fb56dc2428e9703f3b,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.7683708, lng: -122.4564649 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3340.838606150309
},
{
_id: 5f2084f656dc2428e96fbe86,
category: [ '5e5150c6c52a3904b74d6ff7', null ],
coordinates: { lat: 37.7669182, lng: -122.4561008 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3349.000719541262
},
{
_id: 5f2084fb56dc2428e9703f3f,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.7669182, lng: -122.4561008 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3349.000719541262
},
{
_id: 5f2084fa56dc2428e9702130,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.7669182, lng: -122.4561008 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3349.000719541262
},
{
_id: 5f2084fb56dc2428e9703ee5,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.7787325, lng: -122.4572683 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3357.3418413767595
},
{
_id: 5f2084f856dc2428e96ff091,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.8049528, lng: -122.4249378 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3377.281713590449
},
{
_id: 5f2084fb56dc2428e9703f73,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.8049528, lng: -122.4249378 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3377.281713590449
},
{
_id: 5f2084fb56dc2428e9703f39,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.7788351, lng: -122.4575644 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3384.6341862170793
},
{
_id: 5f14aa92745456119cf27701,
category: [ '5e5150f0c52a3904b74d6ffb', null ],
coordinates: { lat: 37.779187, lng: -122.4577491 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3405.9730381738473
},
{
_id: 5f2084fb56dc2428e9703f21,
category: [ '5e5150bcc52a3904b74d6ff6', null ],
coordinates: { lat: 37.8034776, lng: -122.4027084 },
location: { type: 'Point', coordinates: [Array] },
calcDistance: 3501.3565554464535
},
]
我想找到一个具有“favTypes”类别的对象,该对象返回
"5e5150bcc52a3904b74d6ff6,5e5150c6c52a3904b74d6ff7,5e5150d6c52a3904b74d6ff8"
搜索在其类别中具有这三个 object_Id 之一的对象。我努力了
jsondatas.filter(jsondata => word.category = favTypes);
但是,它返回的是 jsondatas 未过滤的对象。有什么办法可以过滤
.indexOf() 在每次迭代作为数组或整个作为字符串 indexOf(), .includes() 或 .match()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句