Question

Let's assume I have a list of Strings: List[String]. And I want to convert it to the interoperable JavaScript array of JavaScript Strings: js.Array[js.String]. How to do that?

Was it helpful?

Solution

The easiest way of doing that is the following: myList.map(x => x: js.String).toArray This can be factored out in an implicit conversion if you need it more than once.

Edit: this answer is obsolete. See @gzm0's answer.

OTHER TIPS

Note that as of Scala.js 0.5.x (current version as of this writing is 0.6.2), there is no difference anymore between java.lang.String and js.String. Hence you can do:

import scala.scalajs.js.JSConverters._ // Scala.js >= 0.5.4

val list: List[String] = ???
val jsList: js.Array[String] = list.toJSArray
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top