How to Split CSV into array

   csvProjectIds = '1,2,3,4';
   arrProjectIds = csvProjectIds.split(',');				

Output

     arrProjectIds[0] = 1
     arrProjectIds[1] = 2
     arrProjectIds[2] = 3
     arrProjectIds[3] = 4

How to Find Element is in Array

   csvProjectIds = '1,2,3,4';
   arrProjectIds = csvProjectIds.split(',');				
   alert(arrProjectIds.indexOf('1'));

Output

 0

The indexOf Returns 0 incase the element is in the array or
-1 if not in the array

Leave a reply