JSFiddle - React, Tailwind, and code Playground
by dshilkret
JavaScript
function checkExtension(list, ext) {
// Split the list into an array of strings
var extensions = list.split(',');
// Trim any extra spaces around the substrings
for (var i = 0; i < extensions.length; i++) {
extensions[i] = extensions[i].trim();
}
// Check if the variable is in the array
for (var i = 0; i < extensions.length; i++) {
if (extensions[i] === ext) {
return true;
}
}
return false;
}
// Example usage
console.log(checkExtension("avi, mp3, mp4", "avi")); // true
console.log(checkExtension("avi, mp3, mp4", "txt")); // false