-1

我需要在 console.log 中过滤从图像中显示的 json 获得的数据。我怎么能做到?

代码

这是我的 .JSON

[
  {
    "category": "FORMULARIOS",
    "items": [
      {
        "label": "Botones",
        "url": "ui-botones"
      },
      {
        "label": "Inputs",
        "url": "ui-inputs"
      }
    ]
  },
  {
    "category": "CORREOS",
    "items": [
      {
        "label": "Facturas",
        "url": "ui-facturas"
      },
      {
        "label": "Movimientos",
        "url": "ui-movimientos"
      }
    ]
  },
  {
    "category": "ALERTAS",
    "items": [
      {
        "label": "Toast",
        "url": "ui-toast"
      },
      {
        "label": "Toolips",
        "url": "ui-toolips"
      }
    ]
  }
]
4

1 回答 1

0

你可以这样做:

var yourJSON ="......";
var newData = filterData('CORREOS');

function filterData(catalogyName) {
    return yourJSON.filter(object => {
        return object['category'] == catalogyName;
    });
}

console.log(newData);
于 2020-05-28T06:49:11.063 回答