in this example i will show you how you can use the javascript function called split() similar to PHP function explode() to create an array from a string

here is the code:

this code lets the user enter a color and it finds a match within the array. it uses the split() function in javascript. similar to php explode() function: <hr />
<script type="text/javascript" language="javascript">
function Search(id){

var Mycolor = document.getElementById(id).value
for (i=0;i<Counts;i++){

if(ColorsArray[i] == Mycolor){
alert('You Entered: ' + Mycolor +' and I found ' + ColorsArray[i] + ' on element #' + i);
return;
}

}
alert('I didnt find ' + Mycolor + ' In the Array');
}
var Colors = 'red|blue|white|green';
var ColorsArray = Colors.split("|");
var Counts = ColorsArray.length;

document.write('Colors Available: ');

for (i=0;i<Counts;i++){
document.write(ColorsArray[i] + ', ');
}

</script>
<br /><br />
Enter Color to find: <input type="text" id="MyColor" /><input type="button" value="Search" onclick="Search('MyColor');" />
<div style="text-align:center;padding:15px;">By <a href="http://www.wallpaperama.com">Wallpaperama.com</a><!-- please dont remove our link--></div>

Demo

this code lets the user enter a color and it finds a match within the array. it uses the split() function in javascript. similar to php explode() function:


Enter Color to find: