How to check if an array contains integer values in JavaScript ?

JavascriptWeb DevelopmentFront End TechnologyObject Oriented Programming

We are required to write a JavaScript function that takes in an array of elements.

Our function should check whether or not the array contains an integer value.

We should return true if it does false otherwise.

Example

The code for this will be −

const arr = ["123", "", "21345", "90"];
const findInteger = (arr = []) => {
   const isInteger = num => {
      return typeof num === 'number';
   };
   const el = arr.find(isInteger);
   return !!el;
};
console.log(findInteger(arr));

Output

And the output in the console will be −

false
raja
Published on 24-Nov-2020 09:45:07
Advertisements