I'm facing an issue with using .map() on a nested array. I initially tried to iterate through my stored data using .map(), and then attempted another iteration within the first one to handle the nested array, but it didn't work as expected.
The "newmap" seems to be functioning correctly, but it produces a nested array. However, when I try to iterate over "newmap" again, it doesn't lead to any changes, which is where the problem arises.
Below, you'll find all the relevant details:
import Head from 'next/head'
import styles from '../styles/Home.module.css'
import React from 'react'
import { bsctokendata } from "../pages/bscdatanew/data";
export default function Home(props) {
const databalone = props.addressbalance;
const datatransone = props.addresstransaction;
return (
<ul>
<h1>Address One</h1>
{databalone.map((balance) => {
return (
<li>{(balance.result * 1e-18).toString()}</li>
)
})}
<div>
<h1>Address Two</h1>
<div>
{datatransone.map(function(d){
return (
<li>{d.result.map((r) =>
<span>{r.from}</span>)}</li>
)
})}
<h1>Address Three</h1>
{datatransone.map(function(d){
return (
<li>{d.result.map((r) =>
<span>{r.hash}</span>)}</li>
)
})}
</div>
</div>
</ul>
);
}
export async function getServerSideProps(context) {
let newmap = bsctokendata.map(function(element){
return (element.whitelistWallets.map(function(r) { return (r)}))
// Handling nested arrays
})
console.log(newmap)
let balance = newmap.map(function(element){
let bscbalance = 'https://api-testnet.bscscan.com/api?module=account&action=tokenbalance&contractaddress=0x0DBfd812Db3c979a80522A3e9296f9a4cc1f5045&address=' + element + '&tag=latest&apikey=E2JAJX6MAGAZUHSYIBZIEMKMNW9NZKPR7I';
return bscbalance;
})
let transaction = newmap.map(function(element){
let bsctransaction = 'https://api-testnet.bscscan.com/api?module=account&action=tokentx&contractaddress=0x0DBfd812Db3c979a80522A3e9296f9a4cc1f5045&address=' + element + '&page=1&startblock=0&offset=1&endblock=999999999&sort=asc&apikey=E2JAJX6MAGAZUHSYIBZIEMKMNW9NZKPR7I';
return bsctransaction;
})
console.log(transaction)
const addressbalance = await Promise.all(balance.map(u => fetch(u)))
const addresstransaction = await Promise.all(transaction.map(e => fetch(e)))
return {
props: {
addressbalance: await Promise.all(addressbalance.map(r => r.json())),
addresstransaction: await Promise.all(addresstransaction.map(p => p.json())),
}
};
}