How would you optimizely loop through the items and nestedItems of each item? The target is to download and store images and PDFs in file system to make them available without internet connection.
Let's assume I have the following data structure:
const items = [
  {
    link: 'example.com/image1.png',
    nestedItems: [
      {
        nestedItemLink: 'example.com/pdf11.pdf',
      },
      {
        nestedItemLink: 'example.com/pdf12.pdf',
      },
    ]
  },
  {
    link: 'example.com/image2.png',
    nestedItems: [
      {
        nestedItemLink: 'example.com/pdf21.pdf',
      },
      {
        nestedItemLink: 'example.com/pdf22.pdf',
      },
    ]
  }
]
How I loop through the higher order array:
const promises = items.map(async (item) => {
  if (!item.link) {
    return item;
  }
  const {
    uri
  } = await FileSystem.downloadAsync(
    item.link,
    `${FileSystem.documentDirectory}${item.link
          .split('/')
          .pop()}`,
  );
  item.link = uri;
  return item;
})
const data = await Promise.all(promises);
 
    