js-sys is a crate, a library in Rust, that contains bindings for JavaScript's standard, built-in objects, including their methods and properties.
The Cargo.toml below enables the use of js-sys.
Cargo.toml
[package]
name = "dom"
version = "0.1.0"
authors = ["www.webassemblyman.com"]
edition = "2019"
[lib]
crate-type = ["cdylib"]
[dependencies]
wasm-bindgen = "0.2.50"
[dependencies.js-sys]
version = "0.3.4"
After enabling the features of the JavaScript objects in js_sys, you can easily use them in your rustwasm programs as shown below.
src/lib.rs
use wasm_bindgen::prelude::*;
#[wasm_bindgen(start)]
pub fn run() -> Result<(), JsValue> {
let array = js_sys::Array::new();
array.push(&"Hello".into());
web_sys::console::log(&array);
Ok(())
}