How to Print Alternate Elements of an Array in JavaScript (DSA)

Published: (March 20, 2026 at 05:11 AM EDT)
1 min read
Source: Dev.to

Source: Dev.to


โš ๏ธ Collection Error: Content refinement error: Error: 429 429 Too Many Requests: you (bkperio) have reached your weekly usage limit, upgrade for higher limits: https://ollama.com/upgrade


๐Ÿงฉ 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. An array of integers arr[] Print the alternate elements of the array (starting from index 0) Example 1: Input: arr[] = [10, 20, 30, 40, 50] Output: 10 30 50

Explanation: Example 2: Input: arr[] = [-5, 1, 4, 2, 12] Output: -5 4 12

1 โ‰ค arr.length โ‰ค 10^5 -10^9 โ‰ค arr[i] โ‰ค 10^9

0 views
Back to Blog

Related posts

Read more ยป