0

I am working on a project in VS built with react (I'm new to react) and I have a loop function that returns json data and I am trying to create a list/array - [1, 2, 3, 4] using the IDs from the loop -

for (const data of data.dataset) {
    ID = data.id;
}

How can I achieve this?

730wavy
  • 944
  • 1
  • 19
  • 57

1 Answers1

1
let myArray = [];

for (let data of data.dataset) {
    myArray.push(data.id)
}

console.log(myArray); // [1, 2, 3, 4]

You can use this method to create a new array with ID's.

Shanu Raj
  • 95
  • 1
  • 8