Tips on transforming a grouped object into a table organized by column with the help of Lodash

Looking at my array data:

[{ id: '1234', year: 2019 , name: 'Test 1- 2019', rate: 1}, 
 { id: '1234', year: 2020, name: 'Test 2 - 2020',  rate: 2 },
 { id: '1234', year: 2020, name: 'Test 3 - 2020', rate : 3 } 
 ...] 

I am trying to display it in a table with this layout:

<table border="1">
  <tr> 
    <th> 2019 </th>
    <th> 2020 </th> 
  </tr> 
  <tr>
    <td> Test 1- 2019</td> 
    <td> Test 2- 2020 </td> 
  </tr>
  <tr>
    <td>  </td> 
    <td> Test 3- 2020 </td> 
  </tr>

</table>

Can anyone provide suggestions on how to achieve this? Thank you! :)

Update: This is what I have attempted so far:

    <table border="1">
      <tr> 
        <th> 2019 </th>
        <th> 2020 </th> 
      </tr> 
      <tr>
        <td> Test 1- 2019</td> 
          <td>  </td> 
      </tr>
       <tr>
        <td> </td> 
          <td> Test 2 - 2020 </td> 
      </tr>
      <tr>
        <td>  </td> 
        <td> Test 3 - 2020 </td> 
      </tr>

    </table>

I am currently using a simple v-for loop in VueJS to iterate through the array.

<table> 
  <tr> 
     <td> ...year </td> 
  </tr>
  <tr v-for="item in arr">
     <td> {{ item.year == "2019" ? item.name : ""}} </td>
     <td> {{ item.year == "2020" ? item.name : ""}} </td>
  </tr>  
</table>

Answer №1

Check out this solution shared by @cmgchess

The method involves utilizing groupBy followed by extracting the Object values and zipping them with lodash

Access the link for more details: shorturl.at/cdxQ6

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

Present Different Content for Visitors Using Ad-Blocking Software

I am currently working on a project that is supported by ads. These ads are subtle and relevant to the content, not obnoxious popups for questionable products. However, since the project relies on ad revenue, users with Ad Blockers unfortunately do not co ...

leveraging hooks in NextJS app router for static page generation

How can I make an action take effect on page-load for the app router equivalent of statically generated pages from static paths in NextJS? Everything is working fine with my page generation: // app/layout.js import Providers from '@/app/Providers&apo ...

The JavaScript file is not compatible with Internet Explorer 9

My website's JavaScript functions normally work on all browsers except for Internet Explorer 9. In IE7 and IE8, they also work normally. After extensive testing, I have concluded that the JS file simply does not work in IE9, but why is that? The curio ...

Clear the local storage once the URL's view has been fully loaded

When retrieving details of a specific item by passing URL parameters stored in local storage, I encountered an issue. I need to delete the local storage variables after the view is loaded. However, what actually happens is that the local storage variable ...

Encountering Server Error 500 while trying to deploy NodeJS Express application on GCP App Engine

My goal is to deploy a NodeJS app on gcloud that hosts my express api. Whenever I run npm start locally, I receive the following message: >npm start > [email protected] start E:\My_Project\My_API > node index.js Running API on por ...

Using React JS, how to easily upload a CSV file to Amazon S3 with your AWS credentials

Seeking guidance on how to utilize AWS credentials to upload a CSV file using React S3 Uploader. The code snippet I've tried so far is as follows: import React, { PureComponent } from "react"; import ReactS3Uploader from "react-s3-uploader"; sav ...

Check if an object is already in an array before pushing it in: JavaScript

Summary: I am facing an issue with adding products to the cart on a webpage. There are 10 different "add to cart" buttons for 10 different products. When a user clicks on the button, the product should be added to the this.itemsInCart array if it is not a ...

Generating a new array and merging different sets of keys together

Is there a way to modify how items are added to a jQuery array? Here is the current code snippet in use: var sub_updated = []; $('.current-sub-items').each(function() { $(this).find('.prod-select').each(function() { if ($(th ...

I need to confirm the validity of minDate and maxDate in a ReactJS component, ensuring that maxDate is always at least 5 years after min

start from today and select a date end 5 years from the starting date I haven't attempted anything yet. Seeking help for a solution. ...

Modify the Div background color by accessing the HEX value saved in a JSON file

(I made a change to my code and removed the br tag from info2) Currently, I have successfully implemented a feature using jQuery that reads color names and hex values from a JSON file, populates them in a drop-down select menu (which is working fine). Now ...

The MUI Autocomplete filterOptions is not effectively filtering out all options as expected

Hey there! I'm facing an unusual situation with my Autocomplete feature, which has been heavily customized to meet certain restrictions and requirements. The issue I am encountering is related to filtering. Despite successfully filtering the results ...

Utilize regular expressions in TamperMonkey to extract specific groups of text

I'm currently working on a TamperMonkey userscript that aims to identify URLs matching a specific pattern, visit these pages, extract relevant information, and then update the link for each URL with the extracted text. I'm facing some challenges ...

Create a pair of divs on your webpage that users can drag around using HTML5

Hello to all HTML5 developers! I am currently facing an issue where I am attempting to designate two separate divs as dragable areas for incoming files. Unfortunately, it seems that only one of them can be active at a time. How can I adjust my code so th ...

Troubleshooting: Why is the AngularUI Modal dialog malfunctioning

I'm currently working on integrating an angularUI modular dialog into my application. Here is a snippet from my controller.js file: define([ 'app' ], function(app) { app.controller('TeacherClasses', [ '$scope', &apo ...

Generate a JSON Object array by collecting data from various elements to make it dynamic

Seeking assistance in creating a dynamic array of JSON objects from the values of various elements. Below are some examples of these elements. There are more elements contributing to the JSON values, but I don't want to repeat the same code three time ...

Problem with Chrome Compatibility for Bootstrap Carousel

My webpage features a carousel implemented as a slider. It seems to be working fine in Firefox and mobile browsers, except for Chrome where it doesn't show up at all. I can't seem to figure out what's causing the issue. Here is the syntax I& ...

Trouble with reading from a newly generated file in a node.js program

Whenever I launch my results.html page, I generate a new JSON file and use express.static to allow access to the public folder files in the browser. Although my application is functioning properly, I find myself having to click the button multiple times f ...

Place a material-ui React component at the center of a footer section

I'm facing a challenge with centering a material-ui Simple Breadcrumbs component within a footer as opposed to having it aligned to the left. Even though I'm new to this, I thought it would be straightforward but I can't seem to figure it ou ...

Error encountered while attempting to install ungit on Windows XP: Unable to locate file directory in C:/Documents

Ungit seems like the ideal tool to gain a better understanding of git, thanks to its graphical interface that simplifies the process. I came across this video explanation which is very helpful in grasping how git functions, even if you don't intend to ...

When a model.find is passed as an argument to be invoked, it results in an error

After working with ExpressJS for a while, I decided to explore using Mongoose alongside it. In the callback of my queries where I handle errors like this: function( error, data ) {...} , I found myself repeating code. To streamline this process, I created ...