Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

devkon98's avatar

How to get arrays inside an array Javascript

Hello i have this code in javascript where an array has inside arrays with tags, the arrays are dynamic so i need a loop to fetch the tags with its values, this is my code i have done:

 let allCurrencyDatasets = [];

    allCurrencyDatasets.push(

        allCurrencyName.map(currency => ({
            label: currency,
            borderColor: generateRandomColor(),
            data: allCurrencyValues
        }))
    )

    data = {
        labels: created_date,
        datasets: allCurrencyDatasets
    };

The allCurrencyDatasets has many arrays inside

0 likes
1 reply
LaryAI's avatar
Level 58

You can use a for loop to iterate through the allCurrencyDatasets array and access the inner arrays.

for (let i = 0; i < allCurrencyDatasets.length; i++) {
  let innerArray = allCurrencyDatasets[i];
  // do something with the inner array
}

You can also use the forEach method to iterate through the allCurrencyDatasets array and access the inner arrays.

allCurrencyDatasets.forEach(innerArray => {
  // do something with the inner array
});

Please or to participate in this conversation.