What is the best way to use console.log for filtering JSON data?

I'm looking to filter the data retrieved from a JSON file that is displayed in the provided image. Can someone guide me on how to achieve this in console.log?

Link to Code

Here's an excerpt from my JSON file:

[
  {
    "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"
      }
    ]
  }
]

Answer №1

If you want to achieve this result, follow these steps:

var jsonData ="......";
var filteredData = extractInformation('CORREOS');

function extractInformation(categoryName) {
    return jsonData.filter(item => {
        return item['category'] == categoryName;
    });
}

console.log(filteredData);

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to select JSON nodes from an Excel table for specific fields?

Greetings! I am new to the world of VBA and JSON, and I have a particular task at hand - parsing a JSON script using a VBA macro. Fortunately, I already have an organized Excel table that links each field with its corresponding JSON path. However, there ...

configuring the width of a modal in bootstrap version 4

In my attempt to personalize the width of a specific modal in Bootstrap, I have explored various resources without success. It seems like my code might be flawed. Below is an excerpt of my HTML: Here are the different approaches I have experimented with: ...

What is the best way to transfer selected rows from table A to table B while adhering to specific conditions?

I need to generate a specific tab based on the data in my JSON response. Here is what I require: markers: [ position: { lat:50.8999208, lng:20.6258000 }, vin: vinfromresponse }, { position: { lat ...

Different return types of a function in Typescript when the parameter is either undefined or its type is explicitly asserted vary

Addressing Complexity This code may seem simple, but the use case it serves is quite complex: type CustomFunction = <B extends ['A']>( param?: B ) => B extends undefined ? 'TYPE_1' : 'TYPE_2' // Usage examples: co ...

Mapping objects in RESTKit framework

My JSON data looks like this: { "predictions":[ { "description":"User1", "id":"75b8c57b4443f4b881f0efc94afd52437232aee9" }, { "description":"User2", "id":"82aa3303704041cda0e4fc34024d383 ...

Python's String Manipulation Techniques

I have unique strings such as - Trang chủ and Đồ Dùng Nhà Bếp which contain special characters. I recently noticed that when these strings are printed, they appear just fine. However, when I convert them to JSON format, the output changes to Trang ...

Angular 8: Efficiently Applying Filters to JSON Data Stored in LocalStorage

In my Angular 8 project, I am storing data in localStorage and need to filter it. However, I am unsure about the method to use. Here is how the localStorage values look: [{id: 9, designation: "spectacle + restaurant", gift: [], type: "Soirée Bon plan", ...

What is the best way to load all Arraylists from the model function?

I am integrating the FlexibleAdapter library to retrieve data from a JSON API in my android studio project. public void createHolderSectionsDatabase(int size, int headers) { databaseType = DatabaseType.MODEL_HOLDERS; HeaderHolder header = null; ...

Setting the date of the NgbDatePicker through code

I have implemented two NgbDatePicker components in my project: input( type="text", ngbDatepicker, #d="ngbDatepicker", [readonly]="true", formControlName='startDate', (dateSelect)='setNew ...

Converting an HTMLElement to a Node in Typescript

Is there a method to transform an HTMLElement into a Node element? As indicated in this response (), an Element is one specific type of node... However, I am unable to locate a process for conversion. I specifically require a Node element in order to inp ...

What are the steps to display a fallback route with TypeScript in Angular 6?

I am currently working with the AppRouting module and have the following code: ... const routes: Routes = [ ... { path: 'events', data: { preload: true }, loadChildren: './events/events.module#EventsModule' }, ... ...

Inquiry on ReactJS conditional rendering concept

Attempting to utilize the <Conditional if={condition}> component in React, which will only render its content if the condition evaluates to true. Referencing the code found on this page, as mentioned in Broda Noel's response to this inquiry. Th ...

unable to retrieve the values of the checkboxes

In the code snippet provided, the goal is to retrieve only the values of the selected checkboxes. However, it seems that only the value of the last checkbox is being retrieved. Let's investigate what might be causing this issue in the code. <div c ...

What is the best way to make my if statement pause until a GET request finishes (GUARD) with the help of Angular?

I am currently working on implementing admin routes for my Angular app, and I have used a role guard to handle this. The code snippet below showcases my implementation: However, I would like the get request to finish executing before the if statement begi ...

JSON-formatted response from a REST API

Recently, I started working with dot net and I have successfully integrated a REST API XML response into my application. However, I have discovered that the REST API also supports JSON. How can I retrieve the JSON response from the REST API? Here is the s ...

Tips for measuring the number of elements in a table using Angular

Need assistance with code for an Angular app that uses ngFor to populate a datatable. The goal is to count the number of columns with the name "apple" and display the total on a card named 'apples'. I attempted to create a function like this: ...

Creating a Cordova application from the ground up, evaluating the options of using ngCordova, Ionic framework, and

With the goal of creating a multiplatform Cordova app for Android, iOS, and Windows, I have been exploring different approaches. My plan is to build an application with 4 or 5 features focused on service consumption (listing, adding, and editing items) wh ...

Declaration of dependencies for NestJS must include dependencies of dependencies

I'm encountering an issue where NestJS is not automatically resolving dependencies-of-dependencies: I have created an AWSModule which is a simple link to Amazon AWS with only a dependency on the ConfigService: @Module({ imports: [ConfigModule], ...

Encountering an issue with Google Auth0 stating that the module "@auth0/nextjs-auth0" does not have the exported member "UserProvider"

I am currently working with next.js and typescript, and I want to incorporate Google Auth0 for authentication. However, I encountered an error: Module '"@auth0/nextjs-auth0"' has no exported member 'UserProvider'. I tried sea ...

Suggested Id Best Practices for JSON API Resources

According to JsonAPI, the recommended type for "id" is a string. identification Every resource object MUST contain an id member and a type member. The values of the id and type members MUST be strings. Why is it important to keep the "id" as a string? S ...