Advertisement
satishfrontenddev5

Untitled

Feb 18th, 2024
29
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. remove integers from a array of different data types in javascript function code .
  2.  
  3. Here's a JavaScript function that removes integers from an array containing different data types:
  4.  
  5. ```javascript
  6. function removeIntegers(arr) {
  7.    return arr.filter(item => typeof item !== 'number' || !Number.isInteger(item));
  8. }
  9.  
  10. // Test the function
  11. const inputArray = [1, 'apple', 2.5, true, 'banana', 3, false];
  12. const outputArray = removeIntegers(inputArray);
  13. console.log(outputArray); // Output: ['apple', 2.5, true, 'banana', false]
  14. ```
  15.  
  16. This function `removeIntegers` takes an array `arr` as input and uses the `filter` method to create a new array containing only elements that are not integers. It checks each item in the array using `typeof` and `Number.isInteger()` to determine if it's not a number or not an integer, respectively. Finally, it returns the filtered array without integers.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement