Pre Exam Test Practice (SSC | Banking | IAS | GATE | State Level | CLAT | Railways | Insurance | Teaching Exams | NDA | Defence | IES |State Exam )

Organizational Research By

Surprising Reserch Topic

how are javascript arrays sparse javascript array

are javascript arrays sparse  using -'javascript,sparse-array'

That is, if I use the current time as an index into the array:

array[Date.getTime()] = value;

will the interpreter instantiate all the elements from 0 to now?  Do different browsers do it differently?

I remember there used to be a bug in the AIX kernel, which would create pseudo-ttys on request, but if you did, say, "echo > /dev/pty10000000000" it would create /dev/pty0, /dev/pty1, .... and then fall over dead.  It was fun at trade shows, but I don't want this to happen to my customers.

asked Sep 8, 2015 by rajesh
edited Sep 9, 2015 by rajesh
0 votes

Related Hot Questions

Government Jobs Opening

Displays: array[0] = zero, typeof(0) == string array[1254503972355] = now, typeof(1254503972355) == string array[3.14] = pi, typeof(3.14) == string Notice how I used syntax, which only gives you the indices that are actually defined. If you use the more common for (var i = 0; i < array.length; ++i) style of iteration then you will obviously have problems with non-standard array indices.
answered Sep 8, 2015 by rajesh
0 votes
You could avoid the issue by using a javascript syntax designed for this sort of thing. You can treat it as a dictionary, yet the "for ... in ... " syntax will let you grab them all. var sparse = {}; // not [] sparse["whatever"] = "something";
answered Sep 8, 2015 by rajesh
0 votes
In general, arrays in JavaScript are sparse, but we can make them as dense as well as : spare array:- var a = new Array(3); a [ , , ] a.length 3 a[0] undefined
answered Sep 8, 2015 by rajesh