본문 바로가기

Web/Javascript

remove array

http://wolfram.kriesing.de/blog/index.php/2008/javascript-remove-element-from-array
[code]
Useful DO
Actually, what I mostly need is: remove a certain value from an array.
I.e. I have some list of visible IDs and I want to remove one because it’s not visible anymore. So just extend the above example a bit.

>>> var visibleIds = [4,5,6];
>>> var idx = visibleIds.indexOf(5); // Find the index
>>> if(idx!=-1) visibleIds.splice(idx, 1); // Remove it if really found!
[5]
>>> visibleIds
[4, 6]
[/code]

http://ejohn.org/blog/javascript-array-remove/

'Web > Javascript' 카테고리의 다른 글

string to json  (0) 2013.09.26
queue  (0) 2013.09.26
callback  (0) 2013.09.26
addEventListener  (0) 2013.09.26
foreach  (0) 2013.09.26