Javascript: array has wrong number of empty slots, am I going bonkers?

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
tomysshadow

Javascript: array has wrong number of empty slots, am I going bonkers?

Unread post by tomysshadow » 2017-04-08, 03:46

I apologize if this is the wrong spot for this, but I didn't know where else to report it.

Open a new tab.
Type this into the console:

Code: Select all

var myArray = new Array();
myArray[15] = "test";
Then, type this into the console:

Code: Select all

myArray
The result of doing this in Vivaldi is:

Code: Select all

[undefined × 15, "test"]
The result of doing this in Pale Moon is:

Code: Select all

Array [ <10 empty slots>, 6 more… ]
It says there are 6 more elements, despite there only being one - and clicking on "6 more..." shows there is only one array element. This is dead simple, and other browsers handle this correctly, so is it safe to say this is a Pale Moon specific issue?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35571
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: Javascript: array has wrong number of empty slots, am I going bonkers?

Unread post by Moonchild » 2017-04-09, 14:15

The total number of elements is correct. Keep in mind that undefined array elements in a sparse array are still elements.
Array, 0-based, 16 elements (0-14 undefined + 15 defined).
Pale Moon only shows the first 10 elements in the console (to prevent huge arrays from flooding the output), and lets you know how many more there are in the array (including empty array elements), being 6. (showing 0-9, leaving [10-14](5)+15(1) = 6 elements)
Clicking more... will open up the object inspector which will only show you the actually defined elements. It still gives you the total array length of 16 there as well.

Everything is perfectly in order, and you're just looking at a different presentation of the same data.
(in other words: 15+1 = 10+6)
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

Locked