Am Unable to Get Data from a Function ;

Hi Legends ,

I want to return two (Multiple ) Data to Outside of function when it Calls from Outside ;
Please see my Code Below ;

Please Read the Comments As
Its working fine inside the Function ;
Not Outside ; Its showing “undefined” ;
Please help me out on this ;

Thanks in Advance :slight_smile:

Could you please show the code in the right way? (CODE-TAGS ?)

Your account does not currently allow posting of links. If you need to post a link of your site or relevant Wix content, you can “break” the URL by adding spaces, like this: www.wix . com/corvid
Am Unable to Paste the Code;
Sorry For the Inconvenience;[Actually its For me];

Hi Can you Connect there ?

Anyone Can Help me out ?

Now you can work with code-tags.

function getName (parameter) {
    $w("#productPage").getProduct()
    .then((product) =>{
 let productName = product.name;
 let productPrice = product.price;
 let ProductNme = productName;       //<---- what is this?
 let ProductPri = productPrice;      //<---- what is this?
 
 var details = [];

        details = [productName, productPrice];
        console.log(details);
 
 return details
    })
    .catch((error)=>{
        console.log(error);
    })
}

Why this?

let ProductNme = productName;
let ProductPri = productPrice;

@russian-dima
Simply
It Will Not Affect Any Code;
We can Delete That Also

@muthu

Perhaps this one?

var details = []

$w.onReady(async function () {
 await getName()
    console.log(details[0]);
    console.log(details[1]);
});


function getName() {
    $w("#productPage").getProduct()
    .then((product) =>{
 let productName = product.name;
 let productPrice = product.price;
        details = [productName, productPrice];
    })
    .catch((error)=>{
        console.log(error);
    })
}

@muthu

Here the right example … :grin:

$w.onReady(async function () {
    console.log(getName())
});


function getName() {
 let productName = "Product-1";
 let productPrice = "Product-Price-1";
 let details = [productName, productPrice];
 return details
}

Good luck and happy coding.

Thanks.
I will check and let you know soon…

@muthu

Already checked and it works :wink: (just take a look onto CONSOLE-OUTPUT).

@russian-dima
For Normal function its working fine;
Please see my code closely ;
its not working for me;

@muthu

Hmmmm ok. What about this?

var Details = [];

$w.onReady(async function () {
    Details = await getName();
    console.log(Details[0]);
    console.log(Details[1]);
    console.log(Details);
});


function getName (parameter) {
    $w("#productPage").getProduct()
    .then((product) =>{
 let productName = product.name;
 let productPrice = product.price;
 
 var details = [];

        details = [productName, productPrice];
        console.log(details);
 
 return details
    })
    .catch((error)=>{
        console.log(error);
    })
}

@russian-dima
TypeError: Cannot read property ‘0’ of undefined ::: On Line 5;

Could you already solve your issue?

Not yet