
- Javascript Basics Tutorial
- Javascript - Home
- Javascript - Overview
- Javascript - Syntax
- Javascript - Enabling
- Javascript - Placement
- Javascript - Variables
- Javascript - Operators
- Javascript - If...Else
- Javascript - Switch Case
- Javascript - While Loop
- Javascript - For Loop
- Javascript - For...in
- Javascript - Loop Control
- Javascript - Functions
- Javascript - Events
- Javascript - Cookies
- Javascript - Page Redirect
- Javascript - Dialog Boxes
- Javascript - Void Keyword
- Javascript - Page Printing
- JavaScript Objects
- Javascript - Objects
- Javascript - Number
- Javascript - Boolean
- Javascript - Strings
- Javascript - Arrays
- Javascript - Date
- Javascript - Math
- Javascript - RegExp
- Javascript - HTML DOM
- JavaScript Advanced
- Javascript - Error Handling
- Javascript - Validations
- Javascript - Animation
- Javascript - Multimedia
- Javascript - Debugging
- Javascript - Image Map
- Javascript - Browsers
- JavaScript Useful Resources
- Javascript - Questions And Answers
- Javascript - Quick Guide
- Javascript - Functions
- Javascript - Resources
Fetch alternative even values from a JavaScript array?
To fetch alternative values, use the array index and check with the following condition −
if(index%2==0) { // code }
The above will display the even values.
Example
Following is the code −
var subjectsName=["MySQL","JavaScript","MongoDB","C","C++","Java"]; for(let index=0;index<subjectsName.length;index++) { if(index%2==0) console.log("Subject name at even position="+subjectsName[index]); }
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo222.js.
Output
The output is as follows −
PS C:\Users\Amit\JavaScript-code> node demo222.js Subject name at even position=MySQL Subject name at even position=MongoDB Subject name at even position=C++
- Related Articles
- Fetch specific values from array of objects in JavaScript?
- What is the alternative of BETWEEN clause to fetch values between a range in MySQL?
- Fetch Numbers with Even Number of Digits JavaScript
- Alternative sorting of an array in JavaScript
- MongoDB query to fetch array values
- Fetch Second minimum element from an array without sorting JavaScript
- MongoDB query to display alternative documents with mapReduce() function and emit even field values
- Finding even length numbers from an array in JavaScript
- Python - Filter even values from a list
- Fetch values by ignoring a specific one in JavaScript?
- Create a record array from a (flat) list of array and fetch specific values based on index in Numpy
- Remove same values from array containing multiple values JavaScript
- MySQL query to fetch specific records matched from an array (comma separated values)
- Extract unique values from an array - JavaScript
- Fetch specific documents with array values in MongoD

Advertisements