如何在 Node.js 中使用多个对象过滤 JSON 数据?

基铉南

我有 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] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

如何在Node.js中过滤JSON数据

如何在node.js中过滤JSON数据?

如何使用node.js中的属性过滤Json数据

如何在Node JS中使用邮递员将数据发布到.json文件

如何在Node.js上使用对象jSON数据进行嵌套循环

如何在 JS 中过滤 JSON 数据

如何在 node.js 中插入 Json 数据?

如何在node.js上查看json数据?

如何在Node.js中使用数据库?

如何在Node.JS中使用JSON

过滤Node.js中的JSON数据(包含对象数组)

如何使用node.js从Yahoo Finance JSON提取数据?

如何在Node.js中使用JSON对象更新mySQL表?

如何在Morris.js中使用本地json数据?

如何在JS函数中使用JSON数据?

如何使用Node.js从Node.js发送和获取JSON数据到HTML

使用Node.js从JSON提取数据

如何仅使用node.js获取嵌套的JSON对象MongoDB的数据

如何在 Node.js 中更新 JSON 对象值

如何在Angular js中使用嵌套对象将ng-repeat中的数据作为JSON数据排序

使用 node.js 连接和聚合 json 对象数据

使用Node.JS将JSON对象数据插入MySQL

如何在 React js 中使用获取的数据过滤数组?

如何使用Node.js从json文件读取数据并将读取的数据显示为html?

如何在电子 renderer.js 文件中使用 Node.js 解析 JSON?

如何使用Angular Js以从node.js服务器检索的表格式显示json数据

如何在HTML中使用Node.js使用mysql数据?

Node.js如何在服务器上的json文件中删除\编辑数据

如何在node.js“ html页面”中显示json字符串化数组数据?