Toon posts:

[JS] Array's deleten

Pagina: 1
Acties:
  • 44 views sinds 30-01-2008

Verwijderd

Topicstarter
Ik ben bezig met een script waarbij het nodig is dat ik bijvorbeeld array[10 en hoger] kan deleten. Hoe delete je een element uit een array?

  • Hangloozz
  • Registratie: Juli 1999
  • Laatst online: 13-07 17:24

Hangloozz

{ @$%&# }

geez, da's toch niet zo moeilijk te vinden op Google :?
ik zocht op 'tutorial javascript delete array', en de voorbeelden overspoelde me.. :{

www.jurgroessen.nl


Verwijderd

asje:
Removing Array Elements
You can delete array elements using one of two methods:

You can use the delete operator
You can use the length property
The delete operator undefines an element but does not affect the length property of an array. For example:
code:
1
2
3
4
5
6
7
8
9
<script type="text/javascript">
<!--
    var exampleArray = new Array("http://","Juicy","Studio",".com");

    delete exampleArray[2]; //Deletes "Studio"
    delete exampleArray[3]; //Deletes ".com"
    document.write('Array length = ' + exampleArray.length);
//-->
</script>
...in the above example, the value of the length property doesn't change.

You can truncate an array by setting the length property to a smaller value than its current value. For example:
code:
1
2
3
4
5
6
7
8
<script type="text/javascript">
<!--
    var exampleArray = new Array("http://","Juicy","Studio",".com");

    exampleArray.length = 2; //Deletes "Studio" & ".com"
    document.write('Array length = ' + exampleArray.length);
//-->
</script>
...in the above example the array is truncated. Any elements that no longer fit are removed from the array.

Verwijderd

Alles over arrays, nouja, bijna alles dan.

Voor zulke fundamentele vragen als die van jou kun je het best even in een reference guide kijken. Zelfs als je al ervaren bent is het verstandig om regelmatig de API, specificaties en whatsnew's door te lezen.

Kijk eens naar Array.slice()

Dit topic is gesloten.