peterschussheim
10/13/2016 - 2:30 AM

indexOf

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);

indexOf

This Gist was automatically created by Carbide, a free online programming environment.

You can view a live, interactive version of this Gist here.