Passing values to Javascript arrays
I'm trying to wrap my head around substituting and combining arrays in Javascript. I've found some code that works to combine arrays, de-duplicate and then sort alphabetically (below). My question is, how can I fill these arrays with other values that are chosen by the user, rather than defining them myself in JS? For instance, if a user clicks a different button, I'd like array1 to be filled with 4 new animal names? I would think there's a way to assign a CSV string to the Captivate variable value and split this into array values in JS. Thanks.
Array.prototype.unique = function() {
var a = this.concat();
for(var i=0; i<a.length; ++i) {
for(var j=i+1; j<a.length; ++j) {
if(a === a
a.splice(j, 1);
}
}
return a;
};
var array1 = ["cat","dog","snake","shark"];
var array2 = ["frog","cow","eagle","shark"];
var arrayFinal = array1.concat(array2).unique();
alert(arrayFinal.sort());
