String.includes vs. Array.includes vs. Object.hasOwn

Benchmark created on


Setup

let s = 'a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z', a = s.split(',');
let i = 0, o = {};
a.forEach(function(l) {o[l] = i++;});

Test runner

Ready to run.

Testing in
TestOps/sec
String.includes
let p = s.includes('z');
ready
Array.includes
let q = a.includes('z');
ready
property lookup
let z = ('z' in o);
ready
hasOwn
let y = Object.hasOwn(o, 'z');
ready
indexOf
let x = (-1 !== a.indexOf('z'));
ready

Revisions

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