I am trying to make a function which checks if the number given is in a specific array.
But when I enter a number which is in the array it still alerts bestaat niet
but it should alert bestaat
Does someone know why it alerts the wrong message?
Here is my array:
var baas = [
2951,
2952,
2953,
2954,
2957,
2961,
2969,
2981,
2984,
2985,
2986,
2988,
2989,
3341,
3342,
3343,
3344,
3351,
3352,
3353,
3354,
3355,
3356,
3361,
3362,
3363,
3364,
3366,
3371,
3372,
3373,
4201,
4202,
4203,
4204,
4205,
4209,
4251,
4254,
4255,
4271,
4273,
4284,
4285,
4286,
4287,
4288,
];
Here is the function:
$('#postalSearch').click(function(){
var postalInput = $("#postalInput").val();
var postalInputSuffix = postalInput.match(/\d+/);
if( $.inArray(postalInputSuffix, baas) !== -1 ) {
alert('bestaat');
} else {
alert('bestaat niet');
}
});
When I fill in 4288
and alert var postalInputSuffix
it does output 4288
but I still get the message bestaat niet
.
Thanks for your time!