I am trying to replicate a recipe app which looks like this:
As you can see I need to display the ingredients in a listed form. I have managed to save all the ingredients in an array called items ( codePen Link below) .
However, when I am getting the data from the API for the recipes (eg. I used: Cake) the ingredient property list (" strIngredient ") contains a lot of empty strings which are getting stored in the items array as well. To remove the unwanted empty strings, I used two methods as shown :
thanks ! it worked. However, can you tell me where I am making a mistake while using the for-in loop and filter method ? Want to make sure that my basic understanding is right.
Since you’re checking strict equality using !==, I imagine you might not have the characters correct. They could be tabs while you’re checking for spaces, or something like that.
It would be much easier to help if you could share the actual text of the array you’re getting from the API rather than a screenshot.
It looks like you build the items array up yourself, and then you’re trying to go back and delete the unneeded items. I think you should try instead to not push them in the first place. (Hint: you can safely ignore them if the ingredient value is an empty string)
Hello! Sorry about the late reply. As someone mentioned, try doing the tutorial on this website. There are a lot of very good courses even on Utube. Just remember: Keep on getting your hands on the keyboard and code stuff yourself. How much ever conceptual videos you cover, you will only truly understand the basics when trying it out yourself. Best of Luck!