How to Print Alternate Elements of an Array in JavaScript (DSA)
đ§© Problem: Alternate Elements of an Array Given an array arr[], your task is to print every alternate element of the array starting from the first element. In other words, print elements at index ...

Source: DEV Community
đ§© Problem: Alternate Elements of an Array Given an array arr[], your task is to print every alternate element of the array starting from the first element. In other words, print elements at index 0, 2, 4, ... and skip the rest. đ„ Input An array of integers arr[] đ€ Output Print the alternate elements of the array (starting from index 0) đ§Ș Examples Example 1: Input: arr[] = [10, 20, 30, 40, 50] Output: 10 30 50 Explanation: Print the first element (10), skip the second (20), print the third (30), skip the fourth (40), and print the fifth (50). Example 2: Input: arr[] = [-5, 1, 4, 2, 12] Output: -5 4 12 â ïž Constraints 1 †arr.length †10^5 -10^9 †arr[i] †10^9 Solution Approch 1