

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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
Execute digits in even places in a JavaScript array?
To access the numbers from the even places, rather than looping through the numbers, loop through the places i.e indexes. If we loop through the numbers, other than the elements in the even places, even numbers will be accessed.
Example
In the following example, a for- loop is used to loop through all the positions and an empty string is used to access the even place values. The conditional statement "if" is used to check whether the positions are even or not. If any position is even then the value corresponding to that position is accessed through the empty string and displayed as shown in the output.
<html> <body> <script> var nums = [15,23,63,53,58,66,77,29,2,110]; for(var i = 0; i< nums.length; i++) { var dis = ""; if((i + 1) %2 === 0) { dis = dis + (nums[i]) + "</br>"; document.write("Digit in " +(i + 1)+ " place is " + " "+dis); } } </script> </body> </html>
Output
Digit in 2 place is 23 Digit in 4 place is 53 Digit in 6 place is 66 Digit in 8 place is 29 Digit in 10 place is 110
- Related Questions & Answers
- Find the sum of digits of a number at even and odd places in C++
- Check whether product of digits at even places of a number is divisible by K in Python
- Check if product of digits of a number at even and odd places is equal in Python
- Check whether product of digits at even places is divisible by sum of digits at odd place of a numbers in Python
- Fetch Numbers with Even Number of Digits JavaScript
- Sum of individual even and odd digits in a string number using JavaScript
- Odd even sort in an array - JavaScript
- Fetch alternative even values from a JavaScript array?
- How to remove the last digit of a number and execute the remaining digits in JavaScript?
- Convert number to a reversed array of digits in JavaScript
- How to execute a cube of numbers of a given array in JavaScript?
- Count odd and even digits in a number in PL/SQL
- Number of even substrings in a string of digits in C++
- Repeating only even numbers inside an array in JavaScript
- Finding even length numbers from an array in JavaScript
Advertisements