6

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?

2 Answers 2

4

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.

Sign up to request clarification or add additional context in comments.

Comments

2

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.