Most effective method for storing large volumes of data within JavaScript objects

To uniquely identify each item, I need to store data using 3 keys. In this example, I am using i, j, z as the keys.

console.time('global1');
var global1 = {};

for (var i = 0; i < 100; ++i) {
  for (var j = 0; j < 100; ++j) {
    for (var z = 0; z < 100; ++z) {
      global1[i] = global1[i] || {};
      global1[i][j] = global1[i][j] || {};
      global1[i][j][z] = global1[i][j][z] = { a: 123456789 };
    }
  }
}

console.timeEnd('global1');

console.time('global2');
var global2 = {};

for (var i = 0; i < 100; ++i) {
  for (var j = 0; j < 100; ++j) {
    for (var z = 0; z < 100; ++z) {
      global2[[i,j,z]] = { a: 123456789 };
    }
  }
}

console.timeEnd('global2');

  1. What kind of optimization is Chrome using to make the first example significantly faster?
  2. What is the most efficient way to store a large amount (or more) of data?

Answer №1

Comparing two different runs of code snippets reveals their strikingly similar execution times. This similarity can be attributed to the fact that the computational complexity of the algorithms is primarily determined by the number of loops, which remains consistent.

When it comes to storing every individual value, there may not be an alternative solution available.

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

Submit the chosen options as an array

I am working with a select list in HTML that looks like this: <input type="checkbox" name="drive_style" value=1 checked />123<br /> <input type="checkbox" name="drive_style" value=2 />123<br /> <input type="checkbox" name="drive ...

In PHP, how can one separate the objects of an array based on their JSON year?

Is there a way to split an array by year based on the date key in ascending order? I've attempted various methods, but haven't been successful. [ { "id": "47", "date": "07/16/2022", "text& ...

Issue with remounting in Nextjs 13

import { useRouter, useSearchParams, usePathname } from 'next/navigation'; export function useQueryParams() { const pathname = usePathname(); const router = useRouter(); const searchParams = useSearchParams()!; const updateQu ...

Possible rephrased version: "Strategies to halt the playback of a screencast.com video that is

I recently uploaded a screencast video to my website and now I'm looking for a way to pause the video when I click on a button. I attempted using some JavaScript code with an onclick event attached to the button. var myVideoPlayer = document.getEleme ...

Tips for expanding the width of Bootstrap modal using animation

Is there a way to resize my Bootstrap 5 modal width and add an animation effect when it expands? I've tried using animate and transition in my style-css but haven't had any success so far. I've looked at other solutions online, but none seem ...

React component's useEffect runs twice when missing dependencies

Hi there, I'm currently facing an issue with the useEffect hook in my code. I have set it without any dependencies because I only want it to run once. The problem arises when the useEffect in the Profiles.js component runs twice, even though I am usin ...

Utilizing JavaScript to call functions from an ASP.NET code file

I am in need of assistance with integrating a JavaScript-based timeline that requires data from an SQL server. I have already developed the queries and JSON conversions using C#.NET functions within a code file associated with an .aspx page. As a newcomer ...

AngularJS - ng-repeat not updating when property array changes

I have a loop in my HTML using ng-repeat: <div class="row"> <div ng-repeat="item in model.painel track by item.codigoIncidente"> <strong>{{item.restante.horaMinutoSegundo}}</strong> </div> </div> In ...

Converting from Async.js parallel to Bluebird: A Step-by-Step Guide

Utilizing async.js allows me to define promises with handlers, providing polymorphism and separating results. Can this be achieved in bluebird as well? async.parallel({ cityPromises: (cb)=>{ City.find({ ...

Unable to establish a connection with the endpoint

I'm encountering an issue while trying to connect to the endpoint on the server. Below is the code snippet: Register.jsx function Register() { const [registerUser, setRegisterUser] = useState({ username: "", email: "", password: "", ...

Is there a way to select an element within a nested list item only when the preceding list item is clicked using Jquery/JavaScript?

I am working with an unordered list that looks like this: <ul> <li><a class="foo" id="one">some text</a></li> <li><a class="foo" id="two">some text</a></li> <li><a class="foo" id="thr ...

Using JavaScript, implement the array.filter method on a JSON array to retrieve the entire array if a specific property matches a given

Help needed with filtering an array: In the user_array, there are arrays that need to be compared to see if the header_info.sap_number matches any value in the valid_sap_number array. If a property value matches anything in the valid_sap_number array, th ...

What causes the Object expected error in jQuery?

Looking for a way to demo horizontal collapse pane with a simple web page that includes html, css, and jquery. <html> <head> <script type="text/javascript" src="//code.jquery.com/jquery-1.10.1.js"></script> <title>Sa ...

Possible revision: "Methods for updating Bootstrap language settings?"

Currently, I am working on a project using ASP.NET Core in combination with Bootstrap. Recently, I successfully integrated localization support by following the guidance provided in this documentation. However, I encountered an issue where the Bootstrap fr ...

Using Angular's $q service in the run block

I have a scenario where I need to load data from local files using the global loadJSON function (though it's not mandatory, it's recommended). Once the data is loaded from all the documents, I want to print the string 'i ve loaded'. T ...

PHP Filling an array using $variables

I'm currently working on building a simple shopping cart, but I've encountered an issue with the product page where users can add more items to their cart than are actually in stock. While I have implemented code on the view cart page to prevent ...

when the submit button is clicked, verify whether the input field is empty

I have exhausted all my options and nothing seems to work. All I want is for the following functionality to be implemented: When a submit button is clicked -> check if a text field is empty -> if it is, display an error alert and prevent advancing t ...

Managing control among various child popups

In the situation I am facing, a parent window with login fields is present. In order to manage its controls, I have stored the window handle using: String parentWindow = idriver.getWindowHandle(); After entering the login credentials, a new popup (let&ap ...

Discover the method to determine the total count of days in a given week number

I am developing a gantt chart feature that allows users to select a start date and an end date. The gantt chart should display the week numbers in accordance with the ISO standard. However, I have encountered two situations where either the start week numb ...

What could be causing my table to not display?

I imported a CSV file with data on time, events, and location. The data was loaded into separate arrays for each column. I attempted to display the arrays as an HTML table using a for loop, but the table is not showing up. What could be causing this issue? ...