If you want to trim elements of an array such that All elements of array should not have space at start or end.
Code:
function trimArray(arr) { for(i=0;i<arr.length;i++) { arr[i] = arr[i].replace(/^\s\s*/, '').replace(/\s\s*$/, ''); } return arr; }
Example :
var triotips = new Array("test"," test1","test2 "," test3 ","test4 test5 "); alert(trimArray(triotips));
Output:
test,test1,test2,test3,test4 test5
If you are looking for trimming Javascript string then see here. Trim Javascript String : Remove space at starting or ending of string
This post was last modified on July 18, 2011 11:23 am