Strategies for managing large arrays in JavaScript

I'm currently working on finding the most effective approach for handling large datasets in JavaScript. Specifically, I am dealing with files containing data spanning four hours read at a 100ms interval.

When all the data is loaded into a one-dimensional array, I encounter difficulties loading it all at once. I am considering splitting it into smaller arrays and wondering if there is an optimal size for these arrays.

I would greatly appreciate any advice on this matter as it is my first time encountering such a challenge. Some of the arrays are just 500kb but still do not load properly as single module exports. Does using AJAX offer better performance for some reason? If so, what might be the underlying reasons?

Answer №1

To retrieve data as a stream, you can utilize the fetch() method along with the .getReader() property found in the Response object. This will provide you with a ReadableStream for reading the data.

fetch("/path/to/server")
.then(response => response.body.getReader())
.then(reader => {
  const processStream = ({done, value}) => {
          if (done) {
            return reader.closed;
          }
          // Handle the `value` which is a chunk of data represented as `Uint8Array`
          return reader.read().then(processStream);
        }
  return reader.read().then(processStream);                
})
.then(() => "Finished reading the stream")
.catch(err => console.error(err));

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

Retrieve a document from a specified URL using JQuery's Ajax functionality

I have an HTML page with an input type text field. I want to be able to paste a URL, for example , into this text field and then click a button labeled "download" in order to download the linked file onto my computer. I am looking to implement this funct ...

Utilizing Repurposed Three.js Shapes

I have been experimenting with Three.js to visualize the path of a particle in a random walk. However, I encountered an issue where geometries cannot be dynamically resized so I had to come up with a workaround by removing the existing line from the scene, ...

What is the best way to apply multiple array filters to an object list in react.js?

Looking to filter an array of items using multiple filter arrays in order to display only the items that match all selected filters. For example: The main array contains a table with the following data: ID TypeID LocationID Name 1 2 ...

placeholder for dropdown selection in Vue.js version 2.0.0

Currently, I am in the process of developing a web application using vuejs 2.0. In order to create a straightforward select input, I employed the following code: <select v-model="age"> <option value="" disabled selected hidden>Select Age&l ...

Deciphering date and time strings in C3

Can someone point me in the direction of documentation explaining how C3 parses datetime strings? It doesn't appear to follow moment.js format, and I'm having trouble finding clear guidance on this. For example, if I have a datetime string like 2 ...

Employing the findOne method repeatedly in a loop can significantly slow down operations in Node.js

Currently, I am working on a project using Node.js in conjunction with MongoDB, specifically utilizing Monk for database access. The code snippet I have is as follows: console.time("start"); collection.findOne({name: "jason"}, function(err, document) { ...

What is the best way to manage asynchronous functions when using Axios in Vue.js?

When I refactor code, I like to split it into three separate files for better organization. In Users.vue, I have a method called getUsers that looks like this: getUsers() { this.isLoading = true this.$store .dispatch('auth/getVal ...

I require my two elements to possess opposing transformations in their coordinates or directions to enable dragging capabilities

Changing the code to move the elements in opposite directions is my goal. I attempted multiplying the second element by -1, but unfortunately, I keep ending up with a NAN or undefined result. Any suggestions on how to achieve the desired effect? ...

The consistency of the input box is lacking

Why is my input box not consistent? Every time I add it, the width increases. I understand it's because of the 'col' control but it's creating a messy layout as shown in the image below https://i.sstatic.net/Q1PHL.png This is the code ...

Mastering the use of npm and sails to create HTML-PDF files effortlessly

UPDATE: I am simplifying my question and will address any other concerns in separate posts if necessary. The initial post was too lengthy, hoping for a straightforward guide on utilizing sails to its fullest potential. Apologies. To begin with, my knowled ...

What is the PHP function to combine strings with matching indexes in an array?

Hey there, so I've got this code snippet that does the job... $Array1 = array("Hello, ", "foo", "The quick brown fox jumped "); $Array2 = array("World!", "bar", "the lazy dog."); $Array3 = array(); for($x = 0; $x < count($Array1); $x++) { $Arr ...

When using nodejs with sqlite3, the first callback parameter returns the class instance. How can this be resolved in order to prevent any issues?

Exploring a TypeScript class: class Log { public id: number; public text: string; construct(text: string){ this.text = text; } save(){ db.run( `insert into logs(text) values (?) `, this.text, ...

positioned the div within the StickyContainer element to ensure it remains fixed in place

I've been working on making a div sticky in a React project. To achieve this, I added the react-sticky package to my project. I placed the div within the StickyContainer component as per the documentation. Although there are no visible errors, the sti ...

If the URL Element is Present in the IMG SRC

Is there a way to write jQuery code that will check if the 'page.php' is present in the src attribute of an image? And if it is, then skip running the 'example function' on that image. But if 'page.php' is not found in the img ...

Creating Transparent Rounded Backgrounds in Google Chrome Packaged Apps: Achieving the same look as Google Hangout app

Looking at the screenshot below, it is evident that the Hangout app has a fully transparent design with background shadow effect applied to it. I have tried various methods in vain, such as applying CSS styling to the "html" and "body" tags of the page, a ...

Having trouble with jQuery's getJSON function throwing an error?

I have been working on a project where I am using the getJSON function to fetch JSON data from an API that I am developing. However, I am facing an issue where the getJSON function always triggers the error handler. Below is the JavaScript code I am using: ...

The configuration for CKEditor5's placeholder feature seems to be malfunctioning

I am currently experimenting with a customized version of CKEditor 5 known as BalloonBlockEditor. Below is the custom build output that I have created: /** * @license Copyright (c) 2014-2023, CKSource Holding sp. z o.o. All rights reserved. * For licens ...

Creating a Route in Angular 2 for a Component other than the one initialized with the bootstrap function

I am currently in the process of working on a project involving Angular2. If you are interested in understanding why I need to do what I am about to explain, please take a look at this issue. The main component in my project is called AppComponent and it ...

Substitute empty spaces and organize the text layout

I'm struggling to figure out how to substitute the whiteSpace in an aggregate request using MongoDB and also how to remove a specific part of a string (most likely requiring regex). Here's an example of my document: { "_id": "57dfa5c9xxd76b ...

Angular - Eliminate objects from an array based on their index matching a value in a separate array

I am facing a challenge with an array of indices and an array of objects: let indices = [1,3,5] let objArray = [{name: "John"}, {name: "Jack"}, {name: "Steve"}, {name: "Margot"}, {name: "Tim" ...