Comments on: Remove an element in a JavaScript Array http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/ Useful tips for developers Tue, 15 Sep 2009 08:08:34 +0000 hourly 1 http://wordpress.org/?v=3.0.1 By: Fabian http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-104782 Fabian Wed, 04 Feb 2009 12:56:11 +0000 http://johankanngard.net/?p=22#comment-104782 great! it was of great aid... great!
it was of great aid…

]]>
By: Nilesh http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-92136 Nilesh Wed, 03 Sep 2008 05:22:18 +0000 http://johankanngard.net/?p=22#comment-92136 I want to remove repeated values in the string. suppose the string is 123:234:123:234 values are repeating I want the output as 123:234 I want to remove repeated values in the string. suppose the string is
123:234:123:234
values are repeating I want the output
as 123:234

]]>
By: Hangman http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-91738 Hangman Sat, 30 Aug 2008 21:51:48 +0000 http://johankanngard.net/?p=22#comment-91738 Works great! Works great!

]]>
By: Tom Van Schoor http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-89867 Tom Van Schoor Tue, 05 Aug 2008 11:28:03 +0000 http://johankanngard.net/?p=22#comment-89867 To make it all complete and tidy: Array.prototype.remove=function(s){ var i = this.indexOf(s); if(i != -1) this.splice(i, 1); } Gigi has a point, but it would have been better if this was "his" contribution. No hard feelings though ^^ To make it all complete and tidy:

Array.prototype.remove=function(s){
var i = this.indexOf(s);
if(i != -1) this.splice(i, 1);
}

Gigi has a point, but it would have been better if this was “his” contribution. No hard feelings though ^^

]]>
By: Tom Van Schoor http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-89861 Tom Van Schoor Tue, 05 Aug 2008 08:51:59 +0000 http://johankanngard.net/?p=22#comment-89861 oops again... Array.prototype.remove=function(s){ var i = this.indexOf(s); if(this.indexOf(s) != -1)this.splice(i, 1); } } oops again…

Array.prototype.remove=function(s){
var i = this.indexOf(s);
if(this.indexOf(s) != -1)this.splice(i, 1);
}
}

]]>
By: Tom Van Schoor http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-89860 Tom Van Schoor Tue, 05 Aug 2008 08:50:12 +0000 http://johankanngard.net/?p=22#comment-89860 Thanks Billis for defending, commenting and breaking down is easy. Some ppl think they have to copy paste stuff without thinking about it. All i put was a suggestion out of my head. Instead of breaking it down like that, rather improve the code so others can learn from it. var i = this.indexOf(s); if(this.indexOf(s) != -1)this.splice(i, 1); } error removed from my comment Thanks Billis for defending, commenting and breaking down is easy.
Some ppl think they have to copy paste stuff without thinking about it.
All i put was a suggestion out of my head.
Instead of breaking it down like that, rather improve the code so others can learn from it.

var i = this.indexOf(s);
if(this.indexOf(s) != -1)this.splice(i, 1);
}

error removed from my comment

]]>
By: Billis http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-89466 Billis Fri, 01 Aug 2008 13:27:08 +0000 http://johankanngard.net/?p=22#comment-89466 Gigi, before do some critics like u.... do it better okay? ;) I like that script... i did just put a "return;" after splice Gigi, before do some critics like u….
do it better okay? ;)

I like that script… i did just put a “return;” after splice

]]>
By: Gigi http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-89256 Gigi Wed, 30 Jul 2008 08:43:35 +0000 http://johankanngard.net/?p=22#comment-89256 Tom Van Schoor, your function is full of errors. i, what's i? index, of course. Improve performance? 2 calls to indexOf, when you have the result in index variable. Tom Van Schoor, your function is full of errors. i, what’s i? index, of course. Improve performance? 2 calls to indexOf, when you have the result in index variable.

]]>
By: Jon http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-87218 Jon Thu, 03 Jul 2008 12:36:33 +0000 http://johankanngard.net/?p=22#comment-87218 a.splice(1,1); // Removes 1 element from index 1 Both those '1's look the same to me... splice(index, number of elements) in case anyone is wondering a.splice(1,1); // Removes 1 element from index 1

Both those ’1′s look the same to me…

splice(index, number of elements) in case anyone is wondering

]]>
By: Deo http://johankanngard.net/2005/11/14/remove-an-element-in-a-javascript-array/comment-page-1/#comment-84198 Deo Fri, 16 May 2008 09:25:42 +0000 http://johankanngard.net/?p=22#comment-84198 This was very helpful ! Thanks. This was very helpful !
Thanks.

]]>