3

I start working with scala.js, and I want to convert Seq to js.Array. I have this sample code:

import scala.scalajs.js
import scala.scalajs.js.annotation._

@JSExportTopLevel("Seqs")
object JsSeqs {

  @JSExport
  def sum(xs: js.Array[Double], ys: js.Array[Double]): js.Array[Double] = {
    val s = Seqs.sum(xs.toSeq, ys.toSeq)
    //how to parse Seq[Double] to js.Array[Double] ???
  }

}

object Seqs {

  def sum(xs: Seq[Double], ys: Seq[Double]): Seq[Double] = {
    xs.zip(ys).map(x => x._1 + x._2)
  }

}

How to do that?

1 Answer 1

7

Here is a way to convert a Seq[Int] to Array[Int]

import js.JSConverters._

val scSeq = Seq(1, 2, 3)

// Seq to js.Array -- Copy to js.Array

val jsArray: js.Array[Int] = scSeq.toJSArray

For your reference visit this page.

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

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.