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 programmatically modifying the AppSetting value in web.config using c#?
- TypeError [ERR_INVALID_CALLBACK]: Callback must be a function. Received undefined
- How to calculate the age from jQuery ui datepicker using c#?
- How to calculate days difference between two dates in c#?
- Changing date format in jQuery ui datepicker
- How to set value to nicedit textarea using jQuery?
- How to load data from json file in angular?
- cannot find module consider using '--resolvejsonmodule' to import module with json extension angular
Related Article