And if you don't need the last element, even faster is to just set the length of the array. Yes, the elements beyond the length will be garbage-collected. What you tried first did delete the array element, but left the length the same, so your array has become 'sparse', which the debugger represents with ellipses.

Since you are the second person in a week to ask this question (oldben IM-ed me about it), maybe we need to start a Javascript FAQ?

On 24 Jan 2006, at 01:49, Adam Wolff wrote:

a.pop() is much faster if you want to just remove the last element.

A

On Jan 24, Cortlandt Winters wrote:

Hi Sarah,

I think you're looking for splice. (I like that name)

a.splice(5,1);

-Cort

On 1/23/06, Sarah Allen <[EMAIL PROTECTED]> wrote:


so... I thought that to remove an item from an array, I could just
delete it, but that appears not to work as I expected.

This little sample program:
<canvas>
<script>
   var a=[0,1,2,3,4,5];
   Debug.write(a.length, a);
   delete a[5];
   Debug.write(a.length, a);
</script>
</canvas

generates this output in the Debugger:
6  [0, 1, 2, 3, 4, 5]
6 [0, 1, 2, 3, 4, ...]

Any one know what I should be doing here to delete an item and make the
array one item shorter?

Thanks,
Sarah

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user


_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to