How to check if js.Any value is a number in ScalaJS
If you have a js.Any value, is there an easy way to check if it is a number?
(this question was originally asked in a crashing room and is being recorded here)
+3
BenjaminJackman
source
to share
1 answer
This question raises 2 points.
-
js. Generally should be avoided. Prefer to use scala instead. Any
-
Anyway, if you are stuck with js.Any, somehow raise it to scala. Anyone then do the usual pattern matching:
def isNumber (x: js.Any): Boolean = { (x: Any) match { case x: Double => true case _ => false } }
+4
BenjaminJackman
source
to share