Currently I am doing the following to check if a String exists in an array:
$('#finance').click(function(){ // Show Finance & OD
console.log('Finance jobs');
for(i = 0; i < jobs.length; i ++){
if(jobs[i].department === "Finance & OD"){
console.log(jobs[i]);
}
}
});
However, I'd like to just check if a sub string exists and for it to not be case sensitive. So I tried this but It did not work:
$('#finance').click(function(){ // Show Finance & OD
console.log('Finance jobs');
for(i = 0; i < jobs.length; i ++){
if(jobs[i].department.toLowerCase().indexOf("Finance & OD") >= 0){
console.log(jobs[i]);
}
}
});
I got this error in the console window: Uncaught TypeError: Cannot read property 'toLowerCase' of undefined
I'm wondering how I could fix my code so that rather checking for the entire string, I would check for part of the String say "Finance" for example and that it would not be case sensitive.