Skip to content

Instantly share code, notes, and snippets.

@devheedoo
Last active December 8, 2016 01:02
Show Gist options
  • Save devheedoo/d853467d1b8eee996a26e02d00f27794 to your computer and use it in GitHub Desktop.
Save devheedoo/d853467d1b8eee996a26e02d00f27794 to your computer and use it in GitHub Desktop.
Notes for compability among browsers

JavaScript

.includes()

// IE8 : custom declaration of indexOf()
if(!Array.indexOf){
  Array.prototype.indexOf = function(obj){
    for(var i=0; i<this.length; i++){
      if(this[i]==obj){
        return i;
      }
    }
    return -1;
  }
};
var aList = ['A', 'B', 'C', 'D', 'E'];
// if (aList.includes('D'))
if (aList.indexOf('D') > -1) {
  alert('D!');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment