Checking if key exists or not in a JavaScript Array? (v6)

Revision 6 of this benchmark created on


Preparation HTML

<script>
var long_text = "the the the the the Ladies others the six desire age. Bred am soon park past read by lain. As excuse eldest no moment. An delight beloved up garrets am cottage private. The far attachment discovered celebrated decisively surrounded for and. Sir new the particular frequently \
indulgence excellence how. Wishing an if he sixteen visited tedious subject it. Mind mrs yet did quit high even you went. Sex against the two however not nothing prudent colonel greater. Up husband removed parties staying he subject mr. \
Shot what able cold new the see hold. Friendly as an betrayed formerly he. Morning because as to society behaved moments. Put ladies design mrs sister was. Play on hill felt john no gate. Am passed figure to marked in. Prosperous middletons is ye inhabiting as \
assistance me especially. For looking two cousins regular amongst. \
Do commanded an shameless we disposing do. Indulgence ten remarkably nor are impression out. Power is lived means oh every in we quiet. Remainder provision an in intention. Saw supported too joy promotion engrossed propriety. Me till like it sure no sons. \
Impossible considered invitation him men instrument saw celebrated unpleasant. Put rest and must set kind next many near nay. He exquisite continued explained middleton am. Voice hours young woody has she think equal. Estate moment he at on wonder at season little. Six \
garden result summer set family esteem nay estate. End admiration mrs unreserved discovered comparison especially invitation. \
Friendship contrasted solicitude insipidity in introduced literature it. He seemed denote except as oppose do spring my. Between any may mention evening age shortly can ability regular. He shortly sixteen of colonel colonel evening cordial to. Although jointure an my \
of mistress servants am weddings. Age why the therefore education unfeeling for arranging. Above again money own scale maids ham least led. Returned settling produced strongly ecstatic use yourself way. Repulsive extremity enjoyment she perceived nor. \
Offices parties lasting outward nothing age few resolve. Impression to discretion understood to we interested he excellence. Him remarkably use projection collecting. Going about eat forty world has round miles. Attention affection at my preferred offending shameless \
me if agreeable. Life lain held calm and true neat she. Much feet each so went no from. Truth began maids linen an mr to after. \
At as in understood an remarkably solicitude. Mean them very seen she she. Use totally written the observe pressed justice. Instantly cordially far intention recommend estimable yet her his. Ladies stairs enough esteem add fat all enable. Needed its design number \
winter see. Oh be me sure wise sons no. Piqued ye of am spirit regret. Stimulated discretion impossible admiration in particular conviction up. \
Do play they miss give so up. Words to up style of since world. We leaf to snug on no need. Way own uncommonly travelling now acceptance bed compliment solicitude. Dissimilar admiration so terminated no in contrasted it. Advantages entreaties mr he apartments do. Limits far yet turned highly repair parish talked six. Draw fond rank form nor the day eat. \
Consulted he eagerness unfeeling deficient existence of. Calling nothing end fertile for venture way boy. Esteem spirit temper too say adieus who direct esteem. It esteems luckily mr or picture placing drawing no. Apartments frequently or motionless on reasonable projecting expression. Way mrs end gave tall walk fact bed. \
Is he staying arrival address earnest. To preference considered it themselves inquietude collecting estimating. View park for why gay knew face. Next than near to four so hand. Times so do he downs me would. Witty abode party her found quiet law. They door four bed fail now have. ";


var words = long_text.split(/\s+/);
array = [];
var i , length = words.length; 
for (i =0; i <  length; i++) {
    array[words[i]]= (array[words[i]] || 0) + 1;
}
second_array = {test: "test"};
</script>

Test runner

Ready to run.

Testing in
TestOps/sec
Using in
var result = "Impression" in array;
var negResult = "zzyzx" in array;
var shortArrayResult = "test" in second_array;
var shortArrayNegResult = "Test" in second_array;
ready
Has the property
var result = array.hasOwnProperty("Impression");
var negResult = array.hasOwnProperty("zzyzx");
var shortArrayResult = second_array.hasOwnProperty("test");
var shortArrayNegResult = second_array.hasOwnProperty("Test")
ready
Array as Map
var result = array["Impression"] === undefined;
var negResult = array["zzyzx"] === undefined;
var shortArrayResult = second_array["test"] === undefined;
var shortArrayNegResult = second_array["Test"] === undefined;
ready
Array as Object
var result = array.Impression;
var negResult = array.zzyzx;
var shortArrayResult = second_array.test === undefined;
var shortArrayNegResult = second_array.Test === undefined;
ready
Using Typeof String Comp
var result = typeof array['Impression'] === 'undefined';
var negResult = typeof array['zzyzx'] === 'undefined';
var shortArrayResult = typeof second_array['test'] === 'undefined';
var shortArrayNegResult = typeof second_array['test'] === 'undefined';
ready

Revisions

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