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

Using Yii to attach an onclick event to CLinkPager for every pager link

Is there a way to execute a function with every pager link click in Yii's CLinkPager? I've tried the following code without success. 'pagerCssClass' => 'pagination', 'afterAjaxUpdate'=>"FB.Canvas.scrollTo ...

I possess an item, but unfortunately, I am only able to save the first object from this possession

I have an object, but I can only save the first item from this object. Interface: export interface PhotoToCreate { albumName: string; albumTitle: string; ImageNameO : string; imageNameT : string; } Component import { Component, OnI ...

Create a basic chart using JavaScript

I am looking to replicate a specific chart using JavaScript. The red point in the chart is variable. So far, I have attempted to create it using the flot library: var d3 = [[7,7]]; $.plot("#placeholder", [{ data: d3, points: { show: true } }], { ...

Can an HTML DOM object be converted to a JSON string using JSON.stringify in JavaScript?

Trying to fetch an external HTML file and convert its body content into a string has been giving me unexpected results. Is there a way to achieve this successfully? var xhr = new XMLHttpRequest(); function loadFile(){ xhr.open("GET", 'index.html ...

Data connections in React Firebase provide essential links between multiple pieces of information

In my React application, there is an Administration area where the Admin user can add items to a large catalog stored in Firebase under "catalogue". When a regular user logs into their account, they can see the list of items added by the Admin and choose ...

Searching for specific data within an embedded documents array in MongoDB using ID

While working with mongodb and nodejs to search for data within an embedded document, I encountered a strange issue. The query functions as expected in the database but not when implemented in the actual nodejs code. Below is the structure of my data obje ...

Why does trying to package a Windows app on OSX prompt a request for Wine installation?

For several months, I have been successfully utilizing Electron on macOS (10.11.6) to create and package both OSX and Windows applications. My current setup includes electron v1.7.3 and "electron-packager" "^8.5.2", all of which have not been updated in a ...

Refresh the information displayed in the open Google Maps Infowindow

Experimenting with extracting JSON data from a bus tracker website and integrating it into my own version using Google Maps. Although not as visually appealing, I'm struggling to update an infowindow while it remains open. Despite finding some example ...

Basic HTML Audio Player Featuring Several Customizable Variables

I have a unique API that manages music playback. Instead of playing audio in the browser, it is done through a Discord bot. Achievement Goal https://i.stack.imgur.com/w3WUJ.png Parameters: current: indicates the current position of the track (e.g. 2:3 ...

Navigating Next.js: Mastering the art of localStorage Access

Currently, I am developing my first member area using next.js. My goal is to store some data in localStorage (such as token, expiresAt, userInfo), which will eventually be moved to an http-only cookie. The code below is generating the error: "LocalStorage ...

What is the best way to use JavaScript in an ASP.NET Controller to navigate to a different webpage?

I'm currently developing a website using Angular 1 with an ASP.NET MVC backend. I'm trying to create a link that will gather certain parameters using JavaScript, retrieve the correct URL from a controller, and then redirect the user to a differen ...

Struggling to display a navigation menu on angular 1 with complex nested json structure

I have set up a navigation bar using JSON data fetched by an Angular service. Everything is working fine with my service and controller, but I am facing difficulty in displaying the nested JSON data in my view. Here is the JSON data: { "menu": [ ...

Error: The window object is not found in this context when initializing the Commerce module from the commerce.export.js file located in the node_modules folder within the @chec

I have been working with the pages router and custom app file (_app.js) https://nextjs.org/docs/pages/building-your-application/routing/custom-app It seems that the issue may be within my _app.js file, where I have the following code: import '../glo ...

Using reduce() to group items in an array based on a specific object property

Creating a new array grouped by the property 'desc' of the objects within an existing array is my current task. Here is how I envision it: const sourceArray = [ { id: 'id1', sourceDesc: 'foo', prop1: 'ignoreme', p ...

Using the first value of an array as a unique key and the second value as its corresponding values on a new array

Below is an array structure: $array1 = array 0 => array 0 => string 'biodata' (length=7) 1 => string 'family_name' (length=11) 1 => array 0 => string 'bi ...

Tips for creating a plug-in plugin and applying the necessary parameters

(function( $ ){ var functions = { init : function( options ) { var settings = $.extend({ //Declaring default settings that can be overridden in the plugin call code: 7, listHe ...

Tips for creating an editable div that can also incorporate a textarea and the option to upload or delete photos

On my website, users can upload images, names, and descriptions which are saved in a MySQL database. The information is then fetched to display on the website. The code below allows users to enter this information and see it displayed when they click the s ...

How to interact with AngularJS drop-down menus using Selenium in Python?

I have been working on scraping a website to create an account. Here is the specific URL: Upon visiting the site, you need to click on "Dont have an account yet?" and then click "Agree" on the following page. Subsequently, there are security questions th ...

Exploring the Concept of Pre-rendering in Next.js Without the Use of SSR or SSG Techniques

Hello JavaScript Community, I've been delving into the world of Next.js and its rendering capabilities, and I find myself pondering about pre-rendering behavior in scenarios where neither SSR (getServerSideProps) nor SSG (getStaticProps/getStaticPath ...

Using Cordova plugman to add the initial platform-specific plugin into the project

Here are the system dependencies: cordova: @7.1.0 plugman: @2.0.0 I am trying to use plugman specifically for installing plugins on a particular platform (such as android). Having reviewed the documentation, I find that the workflow and usage is not en ...