Lists, [].indexOf vs in operator

Benchmark created by Andy E on


Preparation HTML

<script>
  var allowedArr = ["A", "ABBR", "ACRONYM", "ADDRESS", "APPLET", "AREA", "ARTICLE", "ASIDE", "AUDIO", "B", "BASE", "BASEFONT", "BDO", "BGSOUND", "BIG", "BLOCKQUOTE", "BODY", "BR", "BUTTON", "CANVAS", "CAPTION", "CENTER", "CITE", "CODE", "COL", "COLGROUP", "COMMENT", "CUSTOM", "DD", "DEL", "DFN", "DIR", "DIV", "DL", "DT", "EM", "EMBED", "FIELDSET", "FIGCAPTION", "FIGURE", "FONT", "FOOTER", "FORM", "FRAME", "FRAMESET", "HEAD", "HEADER", "HGROUP", "HN", "HR", "HTML", "I", "IFRAME", "IMG", "INPUT", "INS", "ISINDEX", "KBD", "LABEL", "LEGEND", "LI", "LINK", "LISTING", "MAP", "MARK", "MARQUEE", "MEDIA", "MENU", "META", "NAV", "NOBR", "NOFRAMES", "NOSCRIPT", "OBJECT", "OL", "OPTGROUP", "OPTION", "P", "PARAM", "PLAINTEXT", "PRE", "Q", "RT", "RUBY", "S", "SAMP", "SCRIPT", "SECTION", "SELECT", "SMALL", "SOURCE", "SPAN", "STRIKE", "STRONG", "STYLE", "SUB", "SUP", "TABLE", "TBODY", "TD", "TEXTAREA", "TFOOT", "TH", "THEAD", "TITLE", "TR", "TT", "U", "UL", "VAR", "VIDEO", "WBR", "XML", "XMP"];
  var allowedObj = {A:undefined,ABBR:undefined,ACRONYM:undefined,ADDRESS:undefined,APPLET:undefined,AREA:undefined,ARTICLE:undefined,ASIDE:undefined,AUDIO:undefined,B:undefined,BASE:undefined,BASEFONT:undefined,BDO:undefined,BGSOUND:undefined,BIG:undefined,BLOCKQUOTE:undefined,BODY:undefined,BR:undefined,BUTTON:undefined,CANVAS:undefined,CAPTION:undefined,CENTER:undefined,CITE:undefined,CODE:undefined,COL:undefined,COLGROUP:undefined,COMMENT:undefined,CUSTOM:undefined,DD:undefined,DEL:undefined,DFN:undefined,DIR:undefined,DIV:undefined,DL:undefined,DT:undefined,EM:undefined,EMBED:undefined,FIELDSET:undefined,FIGCAPTION:undefined,FIGURE:undefined,FONT:undefined,FOOTER:undefined,FORM:undefined,FRAME:undefined,FRAMESET:undefined,HEAD:undefined,HEADER:undefined,HGROUP:undefined,HN:undefined,HR:undefined,HTML:undefined,I:undefined,IFRAME:undefined,IMG:undefined,INPUT:undefined,INS:undefined,ISINDEX:undefined,KBD:undefined,LABEL:undefined,LEGEND:undefined,LI:undefined,LINK:undefined,LISTING:undefined,MAP:undefined,MARK:undefined,MARQUEE:undefined,MEDIA:undefined,MENU:undefined,META:undefined,NAV:undefined,NOBR:undefined,NOFRAMES:undefined,NOSCRIPT:undefined,OBJECT:undefined,OL:undefined,OPTGROUP:undefined,OPTION:undefined,P:undefined,PARAM:undefined,PLAINTEXT:undefined,PRE:undefined,Q:undefined,RT:undefined,RUBY:undefined,S:undefined,SAMP:undefined,SCRIPT:undefined,SECTION:undefined,SELECT:undefined,SMALL:undefined,SOURCE:undefined,SPAN:undefined,STRIKE:undefined,STRONG:undefined,STYLE:undefined,SUB:undefined,SUP:undefined,TABLE:undefined,TBODY:undefined,TD:undefined,TEXTAREA:undefined,TFOOT:undefined,TH:undefined,THEAD:undefined,TITLE:undefined,TR:undefined,TT:undefined,U:undefined,UL:undefined,VAR:undefined,VIDEO:undefined,WBR:undefined,XML:undefined,XMP:undefined};
  var allowedReg = /^(?:A|ABBR|ACRONYM|ADDRESS|APPLET|AREA|ARTICLE|ASIDE|AUDIO|B|BASE|BASEFONT|BDO|BGSOUND|BIG|BLOCKQUOTE|BODY|BR|BUTTON|CANVAS|CAPTION|CENTER|CITE|CODE|COL|COLGROUP|COMMENT|CUSTOM|DD|DEL|DFN|DIR|DIV|DL|DT|EM|EMBED|FIELDSET|FIGCAPTION|FIGURE|FONT|FOOTER|FORM|FRAME|FRAMESET|HEAD|HEADER|HGROUP|HN|HR|HTML|I|IFRAME|IMG|INPUT|INS|ISINDEX|KBD|LABEL|LEGEND|LI|LINK|LISTING|MAP|MARK|MARQUEE|MEDIA|MENU|META|NAV|NOBR|NOFRAMES|NOSCRIPT|OBJECT|OL|OPTGROUP|OPTION|P|PARAM|PLAINTEXT|PRE|Q|RT|RUBY|S|SAMP|SCRIPT|SECTION|SELECT|SMALL|SOURCE|SPAN|STRIKE|STRONG|STYLE|SUB|SUP|TABLE|TBODY|TD|TEXTAREA|TFOOT|TH|THEAD|TITLE|TR|TT|U|UL|VAR|VIDEO|WBR|XML|XMP)$/i
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Using Array with .indexOf
allowedArr.indexOf("SPAN") > -1;
ready
Using Object with in operator
"SPAN" in allowedObj;
ready
Using Object with hasOwnProperty
allowedObj.hasOwnProperty("SPAN")
ready
Using a regular expression
allowedReg.test("SPAN")
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.