Quote:
Originally Posted by triko
But if I want put in array2 only the even or odd number???
How to do???
|
The
.slice method generates a new array from an existing one.
For recent browsers that support the
.filter method, you can just do:
Code:
<script type="text/javascript">
array1 = [ 1, 4, 2, 13, 5 ];
odds = array1.filter( function( elem ){ return elem % 2; } )
alert( odds );
</script>