Print all Even Numbers in a Range in JavaScript Array Last Updated : 15 Feb, 2024 Summarize Comments Improve Suggest changes Share Like Article Like Report We have to find all even numbers within a given range. To solve this question we are given the range(start, end) in which we have to find the answer. There are several ways to print all the even numbers in a range in an array using JavaScript which are as follows: Table of Content Using for Loop in JavaScriptUsing While Loop in JavaScriptUsing forEach Loop in JavaScriptUsing for Loop in JavaScriptIn this method, a "for" loop is used to iterate through a given range of numbers. It identifies even numbers within this range by checking if the current number's remainder, when divided by 2, is zero. If so, it prints the even number. Example: To print all the even number within a specific range in JavaScript using for loop. JavaScript // JavaScript program to print all even // numbers in a range using for loop let start = 4; let end = 15; for (let even = start; even <= end; even += 2) { console.log(even); } Output4 6 8 10 12 14 Time Complexity: O(n) Space Complexity: O(1) Using While Loop in JavaScriptIn this method, we uses a "while" loop to iteratively identify and print even numbers within a specified range. The loop continues until the end of the range is reached. Example: To find all the even number in a range in JavaScript using while loop. JavaScript // JavaScript program to print even // numbers in a given range using while loop let start = 4; let end = 15; let current = start; while (current <= end) { if (current % 2 === 0) { console.log(current); } current += 2; } Output4 6 8 10 12 14 Time Complexity: O(n) Space Complexity: O(1) Using forEach Loop in JavaScriptIn this method, it combines a "for" loop with a "forEach" loop to identify even numbers in a given range. It populates an array with even numbers and then prints each element using "forEach". Example: To print all the even numbers in a range in JavaScript using forEach loop. JavaScript // JavaScript program to print even // numbers in a given range using forEach loop let start = 4; let end = 15; let evenArray = []; for (let num = start; num <= end; num++) { if (num % 2 === 0) { evenArray.push(num); } } evenArray.forEach((evenNumber) => { console.log(evenNumber); }); Output4 6 8 10 12 14 Time Complexity: O(n) Space Complexity: O(n) Comment More infoAdvertise with us Next Article Print all Negative numbers in a Range in JavaScript Array A abhinavsrivastava1920 Follow Improve Article Tags : JavaScript Web Technologies Similar Reads Print all Odd Numbers in a Range in JavaScript Array Odd numbers are numbers that cannot be divided into equal parts. If we divide the odd number by 2, the remainder is 1. In JavaScript, if we want to print all Odd numbers in a range, we can print it by iterating over the array, applying the condition, and printing the odd numbers. There are various a 4 min read Print all Positive Numbers in a Range in JavaScript Array To print all the possible numbers in a range from the JavaScript array, we need to iterate over the array and apply the condition to filter out the positive numbers. Once the elements are extracted, we can print them in the console. Example:Input: arr = [-22, 45, 63, -88, -69]Range = [1 to 70]Output 3 min read Print all Negative numbers in a Range in JavaScript Array To print all the negative numbers in a range from the JavaScript array, we need to iterate over the array and apply the condition to filter out the negative numbers. Once the elements are extracted, we can print them in the console. Example:Input: arr = [-22, 45, 63, -88, -69]Range: [-1 to -70]Outpu 3 min read JavaScript program to print even numbers in an array Given an array of numbers and the task is to write a JavaScript program to print all even numbers in that array. We will use the following methods to find even numbers in an array: Table of Content Method 1: Using for Loop Method 2: Using while Loop Method 3: Using forEach LoopMethod 4: Using filter 5 min read Print all Positive Numbers in JavaScript Array In JavaScript, arrays are the data structures used to store multiple elements. In some cases, we need to extract the elements that satisfy a specified condition. We can use a condition to extract all the positive numbers from an array with the below approaches. Example:Input: arr = [-1, -12, 35, -8, 3 min read Print all Negative Numbers in JavaScript Array In JavaScript, arrays are the data structures used to store the elements. In some cases, we need to extract the elements that satisfy the condition. To print all the negative numbers from the JavaScript array, we need to iterate over the array and apply the condition to filter out the negative numbe 4 min read Like