Free string-indexed Array memory

  • Thread starter plumpickerpurplepaws
  • Start date
P

plumpickerpurplepaws

In this example:

var x = [];
x[0] = "Hello World!";
x[1] = "Hello Alien!";
x["world"] = 1;
x["human"] = 0;
x["alien"] = 0;

how would I free only the memory allocated at line 5 (i.e. x["human"])?
 
R

RobG

In this example:

Incidentally, *all* array indexes are strings. If you specify a
number, it is converted to a string.
var x = [];
x[0] = "Hello World!";
x[1] = "Hello Alien!";
x["world"] = 1;
x["human"] = 0;
x["alien"] = 0;

how would I free only the memory allocated at line 5 (i.e. x["human"])?

delete x.human;
 
V

VK

var x = [];
x[0] = "Hello World!";
x[1] = "Hello Alien!";
x["world"] = 1;
x["human"] = 0;
x["alien"] = 0;

alert(x.length); // 2

Only x[0] and x[1] will become array elements. "world", "human",
"alien" are being added as custom property of x object but do not
become array elements.

Possibly it is what you wanted to, but worth to mention.


delete operator can be used in either case
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,571
Members
45,045
Latest member
DRCM

Latest Threads

Top