Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7762171
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T14:19:39+00:00 2026-06-01T14:19:39+00:00

I was wondering if any one knows how memory is handled with JS arrays

  • 0

I was wondering if any one knows how memory is handled with JS arrays if you have an array that starts with a high value.

For example, if you have:

array[5000] = 1; 

As the first value in the array, everything before 5000 simply does not exist, will the amount of memory assigned to the array cater for the unassigned 4999 positions prior to it… or will it only assign memory to the value in the array for [5000] ?

I’m trying to cut down on the amount of memory used for my script so this led to me wondering about this question 🙂

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T14:19:41+00:00Added an answer on June 1, 2026 at 2:19 pm

    When assigning a value to the 5000th key, not the whole array is populated:

    var array = [];     // Create array
    array[5000] = 1;
    '1' in array;       // false: The key does not exists
    Object.keys(array); // 5000 (it's the only key)
    

    If you want to blow your new browser with arrays, populate a typed array:

    var array = new ArrayBuffer(6e9); // 6 Gigs
    

    Both can be verified easily in Chrome: Open the console and memory console (Shift+Esc), and paste the code. window.a=new Array(6e9); or window.a=[];window[6e9]=1; doesn’t result in a significant memory increase,
    while window.a=new ArrayBuffer(6e9); crashes the page.

    PS. 6e9 === 6000000000

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was just wondering if any one knows of a good script to emulate
I'm wondering if any one knows of a JS function to convert a json
I was wondering whether anyone knows of any tools available that perform the task
I was wondering if anyone knows of any large sites that use progressive enhancement/CSS3?
I'm wondering if any one knows a javascript formula which calculates the max number
I was wondering if anyone knows of any good Open Source distributed computing projects?
I was wondering if anyone knows an easy way to do this. I have
In one of my process I have this SQL query that take 10-20% of
just wondering if anyone knows of any pre built content switchers powered by jquery
I am wondering would this make any real efficieny difference (ie computation time, memory

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.