Next JS restricts XLSX to return only 100 objects as an array of arrays

I've developed a file upload system that reads Excel files and uploads data to a database (using Mongoose). After implementing the code, I noticed that when I use console.log(sheetData), it returns an array of arrays with objects inside. Each internal array contains only 100 objects before creating a new array. Below is the code snippet along with images illustrating the issue.

Code

//Excel Upload
  const handleExcelSubmit = async (e) => {
    e.preventDefault();
    const reader = new FileReader();
    reader.onload = async (e) => {
      const data = e.target.result;
      const workbook = xlsx.read(data, { type: "binary" });
      const sheetNames = workbook.SheetNames[0];
      const workSheet = workbook.Sheets[sheetNames];
      const sheetData = xlsx.utils.sheet_to_json(workSheet, {
        header: "1",
      });
      const headers = sheetData[0];
      return convertToJson(headers, sheetData); // <--- Why does it return an array of arrays???
      dispatch(importExcel(sheetData)); // currently disabled for debugging
    };
    reader.readAsBinaryString(excelFile);
  };

  //Converts data to json. Unsure if this is necessary as I received the same data without using this function
  const convertToJson = async (headers, data) => {
    const rows = [];
    data.forEach(async () => {
      let rowData = {};
      rows.forEach(async (element, index) => {
        rowData[headers[index]] = element;
      });
      rows.push(rowData);
    });
    setTableData(rows);
    console.log(tableData);
    return rows;
  };

Image - Array of Arrays

https://i.stack.imgur.com/klmZR.png https://i.stack.imgur.com/HoZ4j.png

Summary

The current behavior involves creating multiple arrays instead of just one containing all 108 objects. Is there a way to modify the code so that only a single array is created with all the objects?

(Due to production considerations, I have hidden sensitive data in the provided images. Apologies for any inconvenience.)

Thank You

Answer №1

After some investigation, I identified the root cause of the problem: it was actually located in my backend code. When sending an array of data, I utilized a 'for loop' to retrieve and upload the data to the database on the backend. The mistake I made was including a response within the loop itself, causing it to break prematurely. This response was simply for checking backend data and served no useful purpose, so I removed it from the loop. Once this unnecessary response was eliminated, the issue was resolved successfully. For anyone encountering a similar problem in the future, it's crucial to thoroughly review your loops to prevent any disruptions during their execution.

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

How can I utilize the context menu feature within a Material React Table row?

I am looking to implement a context menu for each row of the MUI Table, but I haven't found a suitable example. Is there native support for row-level context menus in the MUI Table, or is it possible to add this functionality per row? For reference, ...

Is it possible to make the v-toolbar-title fixed within a v-navigation-drawer using Vuetify?

Can the <v-toolbar-title> be fixed within a <v-navigation-drawer>? <v-card class="d-inline-block elevation-12"> <v-navigation-drawer hide-overlay permanent stateless height="440" value="true"> <v-toolbar color="whi ...

Loop through the tabs array and display varying views based on conditionals

I am currently working on building tabs and tab panels iteratively to display information, but I am facing issues in getting the desired output. For each name in a list, I need to create a tab and a corresponding tab panel underneath it. For example, the ...

Best method for simultaneously calling multiple routes in Node.js and Express

What is the best approach for handling multiple routes simultaneously in Node.js and Express? For instance, if I have two routes defined as app.get('/', routes.views.index); and app.all('/header', routes.views.header); I want both route ...

Serverless Functions in ZEIT Now - Customizing Routes with Parameters

I successfully implemented 4 serverless routes /api/list (GET) /api/add (POST) /api/update/:id (PUT) /api/remove/:id (DELETE) These routes were added to the api/now.json file in the following format: {"src": "/api/list", "dest": "./list.js", "methods": ...

Fixed width for the last column in DataTables

Here's the scenario: I have a jQuery script that loads DataTables, and I know how to set the "aoColumns" : "sWidth" parameter to fix the width of a specific column, which is working fine. However, my issue arises from having multiple tables with var ...

Dealing with errors when there is no data present in the API feed is a crucial aspect of managing the

I'm encountering an issue with my API feed into Excel. Everything works smoothly, but sometimes when the JSON API Feed returns no data, I receive an error box that disrupts the flow of the excel feed. I've tried numerous error handling methods wi ...

JavaScript function to provide a range of numbers based on a specified number and step value

I am looking for a solution to dynamically generate content based on the number of slides/steps using JavaScript. Any suggestions on how to best achieve this? Thanks in advance! switch(this.currentSlide) { case 1: return '1-12'; ...

Error: The function referenced is not defined when the page loads

Trying to incorporate two different script tags in a single HTML page has been quite a task for me. The first script tag contains the location of a JS file that I need to use for a specific function, while the second script tag is where I have written anot ...

Issue encountered when attempting to assign an empty array with an array of objects following an asynchronous API request using a setter function in a React hook

I am currently working with next.js 10 and I would like to populate the deliveryAddressArray after the page has been mounted. However, I seem to be missing something. Below is my address.js page: const [deliveryAddressArray, setDeliveryAddressArray] = use ...

How can you optimize the storage of keys in JS objects?

Just pondering over this scenario: Consider a line definition like the one below, where start and end are both points. let ln = { s: {x:0, y:0}, e: {x:0, y:0}, o: 'vertical' } Now imagine having a vast array of lines, how can we sav ...

What is the process for changing the background color when a button or div is pressed, and reverting the color back when another button or div is

Looking to customize a list of buttons or divs in your project? Check out this sample layout: <button type="button" class="btn" id="btn1">Details1</button> <button type="button" class="btn" id="btn2">Details2</button> <button ty ...

Make sure to update the package.json file at multiple locations following the execution of the "npm i" command

My goal is to automatically detect any newly installed packages based on my package.json file. This way, whenever I run "npm i", the new package will be added not only to the usual "dependencies" section but also to a custom section called "extDependenci ...

How to display content in separate divs using jQuery hover functionality

I'm in the process of creating my online portfolio by using bootstrap and jquery. I have a series of images arranged side by side with each other, and I want to make the description for each image appear when that specific image is hovered over. Each ...

Php file not receiving data from ajax post method

forget.php PHP: if (! (empty($_POST['emailforget'])) ) { echo "here in the function"; } else { echo "here"; } AJAX: $("#passreset").on('click', function(e) { var emailforget = $("#tempemail").val(); alert(emailforget); ...

Is there a way to utilize ajax to submit a form and upload a file to a spring controller?

I have a form with four fields: file, name, type (as a string), and taskInstanceId. <form> <table id="documentDetailsTable"> <tr> <td>Document Type: </td> <td><select id="documentType" ...

JavaScript - undefined results when trying to map an array of objects

In the process of passing an object from a function containing an array named arrCombined, I encountered a challenge with converting strings into integers. The goal is to map and remove these strings from an object titled results so they can be converted i ...

Maintaining DOM modifications once a link has been clicked and the Back button is pressed

Is there a way in JavaScript to prevent appended items from disappearing when the user clicks another link and then presses the Back button after using jQuery's appendTo() method to add items to an unordered list? ...

Enhancing performance by dynamically updating DOM elements when they come into view during scrolling

Currently, I am in search of an efficient algorithm to dynamically load background-images for a group of <li>'s but I am encountering some efficiency issues. The code I am using at the moment is as follows: function elementInView($elem, vps, vp ...

Generating multiple div elements within an AJAX iteration

Currently, I am retrieving data from the server side using AJAX. My goal is to populate data from a list of objects into divs but I am facing an issue where I cannot create the div while inside the foreach loop. $(document).ready(function () { var ...