Created
October 10, 2017 07:47
-
-
Save ytyng/8b9b0d18f3426d9ee1eb451cdce0e2f6 to your computer and use it in GitHub Desktop.
Adobe inDesign用。Array.indexOf が実装されてないので、作る
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adobe inDesign 用 | |
// Array.indexOf が実装されてないので、作る | |
Array.prototype.indexOf = function(item){ | |
for(var i = 0; i<this.length; i++) { | |
if(this[i] === item) { | |
return i; | |
} | |
} | |
return -1; | |
} | |
Array.prototype.includes = function(item){ | |
for(var i = 0; i<this.length; i++) { | |
if(this[i] === item) { | |
return true; | |
} | |
} | |
return false; | |
} | |
var a = [1,2,3]; | |
alert("indexOf(2):" + a.indexOf(2)); | |
alert("indexOf(4):" + a.indexOf(4)); | |
alert("includes(2):" + a.includes(2)); | |
alert("includes(4):" + a.includes(4)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment