-2

I need to filter in the console.log the data that I get from the json that I show in the image. How could I do it?

Code

This is my .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"
      }
    ]
  }
]
Vega
  • 27,856
  • 27
  • 95
  • 103
Maiki
  • 15
  • 4

1 Answers1

1

You can do like this:

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

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

console.log(newData);
Don Lee
  • 465
  • 2
  • 11