A
aliensite
I am trying to pass arrays of various lengths to a function.
However the values are read as a string.
What is the easiest way to pass the values?
<script type="text/javascript">
<!--
function foo() {
var args = "start ";
for( var i=0 ; i < arguments.length; i++ ) {
if(i==0)
args += arguments;
else if(i%2) // odd
args += ' (' + arguments;
else
args += ', ' + arguments + ')';
}args += ' end';
return args;
}
myArray1 = new Array('x', 2, 3)
myArray2 = new Array('y', 5, 7, 11, 13)
alert(foo(myArray1)); // start 1,2,3 end
alert(foo(myArray2)); // start 2,3,5,12,13 end
// alerts should be: start 1 (2, 3) end
// start 2 (3, 5) (12, 13) end
// -->
</script>
However the values are read as a string.
What is the easiest way to pass the values?
<script type="text/javascript">
<!--
function foo() {
var args = "start ";
for( var i=0 ; i < arguments.length; i++ ) {
if(i==0)
args += arguments;
else if(i%2) // odd
args += ' (' + arguments;
else
args += ', ' + arguments + ')';
}args += ' end';
return args;
}
myArray1 = new Array('x', 2, 3)
myArray2 = new Array('y', 5, 7, 11, 13)
alert(foo(myArray1)); // start 1,2,3 end
alert(foo(myArray2)); // start 2,3,5,12,13 end
// alerts should be: start 1 (2, 3) end
// start 2 (3, 5) (12, 13) end
// -->
</script>