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
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
- How to get thumbnail from vimeo video URL in Python?
- Remove all special characters, punctuation except spaces from string - Python
- OSError: cannot write mode RGBA as JPEG- Python
Related Article