In this article we will discuss implementing how to filter odd number using from array in JavaScript. Below example we are using a callback function Isodd it will result the odd numbers.
Example:
<script type="text/javascript">
function Isodd(value, index, array) {
if (value % 2 == 1) {
return true;
}
else {
return false;
}
}
// Source array
var myArray = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
// Pass the callback function asargument to the filter method
var result = myArray.filter(Isodd);
alert(result);
</script>
Output:
Post your comments / questions
Recent Article
- How to enable Search Feature in Django admin?
- How to check PAN-Aadhaar is Linked or NOT?
- How to customize pagination for django admin?
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
Related Article