/ Published in: JavaScript
Released into the public domain. array_to_modify is required; remove_empty_items is an optional boolean argument. find_index is required because some versions of IE don't feature Array.indexOf.
Expand |
Embed | Plain Text
function find_index(array, string) { var i = 0; for(i=0;i<array.length;i++) { if(array[i]==string) break; } return array[i] == string ? i : -1; } function array_unique(array_to_modify, remove_empty_items) { new_array = []; for(var i=0;i<array_to_modify.length;i++) { if(find_index(new_array, array_to_modify[i])==-1&&((remove_empty_items&&remove_empty_items==true&&array_to_modify[i].toString().replace(/\s/g, '')!='')||!remove_empty_items)) new_array[new_array.length] = array_to_modify[i]; } return new_array; }
You need to login to post a comment.
