Check if char is number (0-9)

Benchmark created on


Setup

let array = ["1","2","3","4","5","6","7","8","9","10","1.2","-0","-1"]
let x;

let emptyArrOfTen = new Array(10).fill(true,0,9)

Test runner

Ready to run.

Testing in
TestOps/sec
Array check
for(let char of array){
	x = !!emptyArrOfTen[char]
}
ready
Char integer value check
for(let char of array){
	x = (char  >= '0' && char  <= '9')
}
ready
Regex
for(let char of array){
	x = (/\d/).test(char)
}
ready
Switch
for(let char of array){
	switch(char){
		case'1':
		case'2':
		case'3':
		case'4':
		case'5':
		case'6':
		case'7':
		case'8':
		case'9':{x=true;break}
		default:x=false
	}
}
ready
String to num native conversion
for(let char of array){
	x = !!(+char)
}
ready

Revisions

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