Heres' a one-liner JS code.
<script> let get_the_odd = () => { let arr = [18, 7, 11, 19, 3]; arr = Math.min(... arr.filter(item => item % 2)); // one-liner JS code. document.write(arr); } get_the_odd(); </script>
Now, let me break the code for you. First, it will filter out all the odd numbers in the array. Next, it finds the minimum value or the smallest odd number in the array.
<script> let arr = [18, 7, 11, 19, 3]; arr = arr.filter(item => item % 2); // filter out all odd numbers. document.write(Math.min(... arr)); // using spread operator with Math.min() method. </script>
Similarly, you can easily filter out only numbers in an Array using JavaScript.
Here's another filter method example, I am sure you will like it. How to filter only 4 letter words from an array in JavaScript. Its so useful, that I created a Cool application called the Random Word Generator.
That's it. Happy coding ☺.