I have an array like this:
var str = "This is an example sentence with the number 1";
var array = str.split(' ');
// array[8] should be 1
Now i want to check, if a certain variable is the same as the value of array[8]. Therefor i thought I could use:
var checkingnumber = 1;
if(array[8] === checkingnumber) {
console.log("success");
return
}
This doesnt seem to work in my Code. So could anyone help me, how to fix that ?
The resulting array will be strings and
===
will compare the type as well. Use==
orparseInt
to make sure you compare apples with apples.