Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- remove integers from a array of different data types in javascript function code .
- Here's a JavaScript function that removes integers from an array containing different data types:
- ```javascript
- function removeIntegers(arr) {
- return arr.filter(item => typeof item !== 'number' || !Number.isInteger(item));
- }
- // Test the function
- const inputArray = [1, 'apple', 2.5, true, 'banana', 3, false];
- const outputArray = removeIntegers(inputArray);
- console.log(outputArray); // Output: ['apple', 2.5, true, 'banana', false]
- ```
- 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