Sorting JSON data in EJS based on categories

Hello, I am facing a dilemma. I need to apply category filtering to a JSON file but I am unsure of how to proceed with it. For instance, I wish to filter the 'vida' category along with its description and price.

I seem to be stuck at this juncture in my assignment and cannot figure out how to make progress.

If there is any online resource or link that can provide answers to these questions, I would greatly appreciate it.

    <div class="container">
        <div class="row">
          <ul>
            <% productsData.forEach(function (product) { %>
            <li>
              <br>
              <div class="col-sm-12 col-md-12 col-lg-12 prdDet">
                      
  
              <div class="col-sm-4 col-md-4 imgcart">
                <img src="../images/prdImages/<%= product.prd_image %>" style="width: 200px;height: 200px;">
              </div>
              <br>
              <div class="col-sm-8 col-md-8">
                <b>Categoria:</b> <%= product.prd_category %> <br>
                <b>Descripcion:</b> <%= product.prd_description %> <br>
                <b>Precio:</b> $<%= product.prd_price %> <br>
              <br>

                <br>
              </div>
              </div>
            </li>
            <% }) %>
      
          </ul>
        </div>
      </div>

[
 {
  "id": 5,
  "prd_category": "VIDA",
  "prd_description": "Content will not be repeated here.",
  "prd_price": 1202,
  "prd_image": "1579108895351.jpg"
 },
 {
  "id": 8,
  "prd_category": "VIDA",
  "prd_description": "Duplicate content will not be displayed again.",
  "prd_price": 2038,
  "prd_image": "1579108921234.jpg"
 } 
 // Remaining data entries for VIDA category excluded for brevity 
 

Answer №1

One day, the answer will come in handy for someone else!

   <%  productsData.filter(function (el) { %>
    <%   return (el.prd_category === "VIDA"); %>
    <% }).map(function(el) { %>
        <b>Category:</b>   <%=  el.prd_category %>  <br>
        <b>Description:</b>   <%=  el.prd_description %>  <br>
        <b>Price: $</b>   <%=  el.prd_price %>  <br>
        <br>
        <% }).sort(); %>

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

Traverse through an array of pictures and add the data to a Bootstrap placeholder within HTML markup

In my quest to create a function that populates placeholders in my HTML with images from an array, I am encountering a problem. Instead of assigning each image index to its corresponding placeholder index, the entire array of images is being placed in ever ...

What is the process for combining two distinct geometries with different materials into a single entity in three.js?

I created a 2D square line diagram followed by another square diagram with a sample image in the center position. However, one of them is visible while the other is hidden. I used two different geometries and materials - one with a line-based material se ...

Navigating between two Vue2 applications

I currently have two applications, app1 and app2. App1 serves as a website at www.wxample.com with a button. My goal is to implement code in app2 that allows me to click the button on app1 and be redirected to the Login Panel in app2 for the workers module ...

Rapidly process likes from all Facebook friends by making multiple JSON requests

I had an interesting idea to develop a program that could analyze the likes of a person's Facebook friends. While there are likely other applications out there claiming to find your "Perfect Match" based on this data, I wanted to create something uniq ...

What is the best way to set the first option in a mat-select to be

My approach to date selection involves using 3 mat-select components for day, month, and year. You can view a demo of this setup here. In an attempt to improve the code, I decided to set the initial options as null by modifying the following lines: allDat ...

How can I send an ArrayList item in the body of an HTTP request (POST) using Flutter?

I have an ArrayList where I store data from my API List<GetTestFeeMap> responseArray =[]; // Storing API response Next, I add data to my ArrayList ➡ responseArray.add(getTestFeeObj!); Now I am attempting to retrieve each encTestId. However, it ...

Is Cookie-session the most ideal choice for React applications?

My NodeJS application currently authenticates users through a third-party app. Once the app retrieves user data, a cookie is generated and sent to the client for React to access the user data from that Cookie. Should I stick with using cookies or consi ...

FireFox is causing issues with both ng-view and Angular functions, rendering them unusable

My AngularJS sample application is running smoothly in Google Chrome, but when I tried to test it in Firefox, I encountered issues with ng-view and other functions not working properly. This is the structure of my application: Index.html <!DOCTYPE ht ...

Learn how to retrieve data from the console and display it in HTML using Angular 4

Need help fetching data inside Angular4 HTML from ts variable. Currently only able to retrieve 2 data points outside the loop. Can anyone assist with pulling data inside Angular4? HTML: <tr *ngFor="let accept of accepts"> ...

Transform JSON data into a Java object with a modified format

I need to convert a JSON string representing an object into a Java object B with a different structure. My current approach involves creating a Java Object A that mirrors the JSON structure, using Jackson for JSON to A conversion, and Dozer with XML mappin ...

What is the best way to transform a JS const into TSX within a Next.js application?

Exploring the code in a captivating project on GitHub has been quite an adventure. The project, located at https://github.com/MaximeHeckel/linear-vaporwave-react-three-fiber, showcases a 3D next.js application that enables 3D rendering and animation of mes ...

Is there a python equivalent for a command that involves sending cookies, making a POST request, and providing authentication information from a JSON file to

The command I have is performing a curl request using data from a JSON file passed to it with the -d option. This method retrieves cookies and saves them in a designated folder. These stored cookies can later be used in subsequent curl requests without ne ...

What is the method for retrieving the name of a canceled file?

When a user clicks on the "Cancel" button during an upload, I am attempting to retrieve the filename of the file that was canceled. However, it seems like the current method I am using (var image_file_name) is not successfully retrieving the name of the ca ...

help a figure leap within the confines of the artwork

Take a look at my jsfiddle here: http://jsfiddle.net/2tLCk/4/ When you press the up button, Mario jumps high into the air and then comes back down. However, if you press it again, he doesn't jump. How can I fix this issue so that when the up button i ...

What is the best method for transforming JSON into JSONP?

I have written the following code to send JSON data to the front end. However, we are facing cross-domain security issues and need to convert it to JSONP. Can anyone suggest what modifications I should make for this conversion? Server-side Code JsonFac ...

What is the best way to navigate from a button in NextJS to another page that I have built within the same application?

As I work on developing a website for a pet rescue charity using Next.js, I am facing an issue with getting my button or link to function correctly. Every time I try to navigate to another page within my Next.js app, I encounter a 404 error stating "This p ...

Position an element in the middle of the range between the tallest and shortest characters

Is there a way to vertically center an element between the tallest and shortest characters of another element (preferably using just CSS, but JavaScript is also acceptable)? I want it to be aligned with the actual text content rather than the line height, ...

The supertest request body cannot be found

Testing my express server POST endpoint using supertest has been a challenge for me. Although everything works perfectly in postman, I encountered an issue when trying to pass body parameters into the test. It seems like the body parameters are not being p ...

Transferring JSON data from Python to PHP 5.3

I'm attempting to transmit a dictionary that was converted to JSON from python to php, but the json_decode function is unable to decode it. I tried decoding it on this online tool and it worked without any issues. Here's a snippet of the JSON da ...

Passing a variable to a different PHP script

I'm facing a dilemma and need some assistance. I'm encountering an issue where a PHP variable (or JavaScript/jQuery) is not being successfully transmitted to another PHP file through an AJAX request that I set up. To provide context, I am in the ...