如何在 JavaScript 中检查数组是否包含整数值?

javascriptweb developmentfront end technologyobject oriented programming更新于 2024/1/9 11:56:17

我们需要编写一个 JavaScript 函数来接收元素数组。

我们的函数应该检查数组是否包含整数值。

如果结果为 false,则返回 true。

示例

其代码为 −

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));

输出

控制台中的输出将是 −

false

相关文章


有用资源