Javascript usuwanie elementu z tablicy: Różnice pomiędzy wersjami
Przejdź do nawigacji
Przejdź do wyszukiwania
Linia 5: | Linia 5: | ||
} | } | ||
</source> | |||
Example: | Example: | ||
<source lang="javascript"> | |||
var selected = Array("element 1","element 2","element 3","bla"); //nasza tablica | var selected = Array("element 1","element 2","element 3","bla"); //nasza tablica | ||
remove_from_array(selected,'element 2'); //usuwam element | remove_from_array(selected,'element 2'); //usuwam element |
Wersja z 01:40, 25 mar 2013
<source lang="javascript">
function remove_from_array(array_to_edit,element_to_remove){ array_to_edit.splice( $.inArray(element_to_remove,array_to_edit) ,1 ); }
</source>
Example:
<source lang="javascript"> var selected = Array("element 1","element 2","element 3","bla"); //nasza tablica remove_from_array(selected,'element 2'); //usuwam element alert(selected); //pokazuje aktualny stan alert(selected.length);
</source>