Print alternate elements of an array | Function to print Alternate elements of the given array ; Print elements at odd positions ; If currIndex stores even index or odd position ; Driver Code
function printAlter ( arr , N ) { for ( var currIndex = 0 ; currIndex < N ; currIndex ++ ) { if ( currIndex % 2 == 0 ) { document . write ( arr [ currIndex ] + " " ) ; } } } var arr = [ 1 , 2 , 3 , 4 , 5 ] var N = arr . length ; printAlter ( arr , N ) ;