Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
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
Returning array values that are not odd in JavaScript
Problem
We are required to write a JavaScript function that takes in an array of numbers.
Our function should construct and return a new array that contains all the numbers of the input array that are not odd.
Example
Following is the code −
const arr = [5, 32, 67, 23, 55, 44, 23, 12];
const findNonOdd = (arr = []) => {
const res = [];
for(let i = 0; i < arr.length; i++){
const el = arr[i];
if(el % 2 !== 1){
res.push(el);
continue;
};
};
return res;
};
console.log(findNonOdd(arr));
Output
[ 32, 44, 12 ]
Advertisements