indexOf
var whitelist = ['.css', '.js']; ///Search an array for a specific value.\\- If the search fails (value not found), return -1.//- If value is found, return the index of the value.
var events = [
{
file: 'css/core.css'
},
{
file: 'js/app.js'
},
{
file: 'index.html'
}
];
var filtered = events.filter(event => {
var ext = event.file.substr(event.file.lastIndexOf('.'));
return whitelist.indexOf(ext) > -1;
});
console.log(filtered);
This Gist was automatically created by Carbide, a free online programming environment.