 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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++
Advertisements
 