Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

array different data inside a single array

how can I get all this array in one array without getting it one after the other like this in the code below? i mean saving the whole data inside one variable without giving a specific index of the array

here’s the code

const favoriteProductone = data?.getAllLikeProduct[0]
const favoriteProductTwo = data?.getAllLikeProduct[1]
const favoriteProductThree = data?.getAllLikeProduct[2]

console.log(favoriteProductone?.Like[0])
console.log(favoriteProductTwo?.Like[0])
console.log(favoriteProductThree?.Like[0]) 

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Just iterate the array like so:

if (!data) {
    throw "data is falsy";
}
data.getAllLikeProduct.forEach(p => {
    console.log(p.Like[0])
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading