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

  • Home
  • SEARCH
  • 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 8945363
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T12:13:46+00:00 2026-06-15T12:13:46+00:00

I would like to have an array based on Uint32Array. The length of the

  • 0

I would like to have an array based on Uint32Array. The length of the array should grow incrementally while amount of its elements grows. At the same time I want “length” property return the number of elements, not the size of the underlying array. For instance:

var a = new myArray();
a.length; // returns 0, the size of underlying array is 10
a.add(0);
a.length; // returns 1, the size of underlying array is 10
...
a.add(9);
a.length; // returns 10, the size of underlying array is 10
a.add(10);
a.length; // returns 11, the size of underlying array is 20

The code below shows how I tried to implement it. The only obstacle is the access to “length” property of the original array. The “parent” word in the code is only for the example. If I replace it with “this.prototype” it says “this.prototype.length” in undefined.

Is it possible to work around it?

var myArray = function() {
this._length = 0;
return this;

// defining the getter for "length" property
Object.defineProperty(this, "length", {
    get: function() {
      return this._length;
    },
};

myArray.prototype = new Uint32Array(myArray.increment);
myArray.increment = 10;
myArray.add = function(val) {
   if (this.length <= parent.length) {
      _a = new Uint32Array(parent.length + myArray.increment);
      _a.set(this);
      this = _a;
    };
   this[this.length++] = val;
};
  • 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-15T12:13:48+00:00Added an answer on June 15, 2026 at 12:13 pm

    This is what I would do:

    function MyArray(increment) {
        var array = new Uint32Array(increment);
        var length = 0;
    
        Object.defineProperty(this, "length", {
            get: function () {
                return length;
            }
        });
    
        this.add = function (value) {
            if (length === array.length) {
                var ext = new Uint32Array(length + increment);
                ext.set(array);
                array = ext;
            }
    
            var index = length++;
            array[index] = value;
    
            Object.defineProperty(this, index, {
                get: function () {
                    return array[index];
                },
                set: function (value) {
                    array[index] = value;
                }
            });
        };
    }
    

    Then you create your array as follows:

    var a = new MyArray(10);
    a.length; // returns 0, the size of underlying array is 10
    a.add(0);
    a.length; // returns 1, the size of underlying array is 10
    ...
    a.add(9);
    a.length; // returns 10, the size of underlying array is 10
    a.add(10);
    a.length; // returns 11, the size of underlying array is 20
    

    You’re doing inheritance in JavaScript wrong. Read about it here.

    You can see the demo here: http://jsfiddle.net/dWKTX/1/

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

Sidebar

Related Questions

I have an array which i would like to sort it based on values
I have an array which i would like to sort it based on values
I have an array of string that I would like to have sorted based
I would like to have an array (or a vector) and at each position
I have the array shown below. I would like to have a resultant array
I would like to have a static char array member initialized in terms of
I have an array that I would like to sort using a date field
I have this array property in my model and would like to see it
I have an array of 50 items and I would like to choose 5
i have an array $mainArray of arrays and i would like to remove /

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.