- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 ]
- Related Articles
- Returning only odd number from array in JavaScript
- Get values that are not present in another array in JavaScript
- Returning values from a constructor in JavaScript?
- Returning just greater array in JavaScript
- Returning the first number that equals its index in an array using JavaScript
- Accessing and returning nested array value - JavaScript?
- Returning reverse array of integers using JavaScript
- Returning the highest value from an array in JavaScript
- PHP Returning values
- Returning Multiple Values in Python?
- Rearrange array such that even positioned are greater than odd in C++
- Matching odd even indices with values in JavaScript
- Returning array of natural numbers between a range in JavaScript
- Odd even sort in an array - JavaScript
- Returning an array containing last n even numbers from input array in JavaScript

Advertisements