|
Q1308 How to you remove an element or item from an array (ie make it smaller)?
irt.org | Knowledge Base | JavaScript | Object | Q1308 [ previous next ]
Q1308 How to you remove an element or item from an array (ie make it smaller)?
You can remove an element by looping through the array and removing
the last item:
<script language="JavaScript"><!--
function RemoveElement(elementnr) {
// elementnr is the number of the element you wish to remove
// the name of the array used here is array
for (elementnr<array.length,elementnr++) {
// assigns the value of elementnr+1 to elementnr, so you move all items by 1
array[elementnr] = array[elementnr + 1];
}
array.length=array.length-1;
// Yes it is as easy as this!
}
//--></script>
|
Submitted by Erik Versaevel
|
|
Copyright © 1996-2008 irt.org, All Rights Reserved.