javascript - Remove element/s from an array -
how can remove item/s array
in javascript ?
function restructurechatboxes() { align = 0; (x in chatboxes) { chatboxtitle = chatboxes[x]; if ($("#chatbox_"+chatboxtitle).css('display') != 'none') { if (align == 0) { $("#chatbox_"+chatboxtitle).css('right', '20px'); } else { width = (align)*(225+7)+20; $("#chatbox_"+chatboxtitle).css('right', width+'px'); } align++; } } }
and want remove chatbox when closed list.
function closechatbox(chatboxtitle) { //here remove list ? $('#chatbox_'+chatboxtitle).css('display','none'); restructurechatboxes(); $.post("chat.php?action=closechat", { chatbox: chatboxtitle} , function(data){ }); }
thanks answers.
first, find index
of element want remove:
var array = [2, 5, 9]; var index = array.indexof(5);
note: browser support indexof limited, not supported in ie7-8.
then remove splice
:
if (index > -1) { array.splice(index, 1); }
the second parameter of splice
number of elements remove. note, splice
modifies array in place , returns new array containing elements have been removed.
Comments
Post a Comment