How are you trying to log it in code? What are the errors?
const { nfts, nftArray } = await getsnft();
This gets the returned nfts and nftArray variables from getsnfts(). After this, you can access these variables directly like console.log(nfts)
. You can use const result = await getsnft();
if this confuses you.
// your function
async function getsnft() {
const nfts = (
await Moralis.Web3API.account.getNFTs({
address: '0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d',
})
).result;
const nftArray = [];
for (let i = 0; i < nfts.length; i++) {
try {
let nft = nfts[i]?.token_address;
nftArray.push(nft);
} catch (err) {
console.log(err);
continue;
}
}
console.log('nftArray', nftArray);
return {
nfts,
nftArray,
};
}
...
// getting the getsnft data from another function
async function another() {
const { nfts, nftArray } = await getsnft(); // get data
console.log("another", nfts);
}