Home > Mobile >  How to loop an ARRAY Contains object and its object property contains an array in reactJS
How to loop an ARRAY Contains object and its object property contains an array in reactJS

Time:06-23

Here is an dateData (3) [{…}, {…}, {…}] this contains three objects and each object value have its own array how to get value from that array 0: {dateValue: Array(13)} 1: {dateValue: Array(13)} 2: {dateValue: Array(13)}

CodePudding user response:

for (const data of dateData) {
  console.log(data.dateValue);
}

CodePudding user response:

const array = [
  { dataValue: [1, 2, 3] },
  { dataValue: [{ obj: 1 }, { obj: 2 }, { obj: 3 }] },
  { dataValue: ["test1", "test2", "test3"] },
];

array?.forEach((element) => {
  element?.dataValue?.forEach((ele) => {
    console.log(ele);
  });
});

  • Related