12/27/2008

How to remove a value from array in javascript ?

Yesterday I was writing javascript and I came across a problem where I had to remove a value from a array in javascript . As usual I tried Array.remove[index] . But it did not work . So how to remove a element from Javascript array ?

Its quite simple . There are two functions which serves your purpose .

splice :

Usage : If you know index of the element / elements to be removed ,
ArrayName.splice(index,Noofelementstoberemoved) ;

E.g : If you want to remove single element from second position in Array=['one','two','three','four','five'];
use Array.splice(1,1) . The result will be ['one','three','four','five']; .

Remove :
If you dont know the index of a particular element to be removed but you know the value of it ,
You can use remove .

Usage : Array.remove('Valuetoberemoved') ;

E.g . To remove fifth element in the above array , use Array.remove('five') ;

5 comments:

duffer Array.remove is not a function

Rarely would a person key in a word that is not related to Viagra if he's planning to buy buy Viagra . Would you? So, what does a Buy Viagra Online vendor do, keeping in mind this particular psychological aspect of the buyers? He would try to inculcate in the content of his site.

Mandatharam...

hồng sâm làm đẹp là một trong những loại thảo dược tự nhiên, có mặt ở rất nhiều quốc gia trên thế giới như Nhật Bản, Hàn Quốc, Hoa Kì... Trong các loại tác dụng làm đẹp của hồng sâm kể trên thì nhân sâm hàn quốc luôn được hàng triệu người trên khắp thế giới săn lùng và tìm kiếm bởi những giá trị tuyệt vời. Từ xưa đến nay những công dụng của loại nhân sâm này vẫn được mọi người lưu truyền và ứng dụng vào trong đời sống đặc biệt là chăm sóc sức khỏe của con người. Củ cách làm đẹp với nhân sâm chính là nhân sâm Hàn Quốc ở dạng tươi chưa qua sơ chế thành các sản phẩm. Củ nhân sâm Hàn Quốc có những vai trò và tác dụng vô cùng to lớn đối với con người.

Post a Comment