Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Array destructuring producing weird results

I am using playwrite-rust crate and executing some Js script into chrome. But I am running into something very weird not sure its about JS, browser, or the crate I am using. Anyhow I will share the problem.

Suppose this is the code I am executing through playwright-rust.

async function search(...args) {
    const [session_id, url] = args;
    console.log(args);
    console.log(args.length);
    console.log(url);
}

How its being called in Rust code:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let args = vec![session_id.clone(), build_url];
let json_result = tab
    .evaluate::<Vec<String>, serde_json::Value>(SEARCH, args)
    .await?;

I am expecting to have url and session_id respective value by array destructuring but that’s not the case. Have a look here what I get in the browser:

enter image description here

args.length produces 1 and url is undefined. What is wrong here?

>Solution :

You have an array that contains another array. You should use

function search(...args) {
    const [[session_id, url]] = args;
}

or

function search(...args) {
    const [session_id, url] = args[0];
}

or

function search(arg) {
    const [session_id, url] = arg;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading