This is what appears when I do
console.log(projects)
However, whenever I try to print anything beyond that, I receive errors or it simply does not print anything.
The things I have tried:
console.log(projects[0]);
console.log(projects.title);
I have also tried using the for each element loop to no luck.
How would I grab the title of each element within this?
This is what appears when I do
console.log(projects)
However, whenever I try to print anything beyond that, I receive errors or it simply does not print anything.
The things I have tried:
console.log(projects[0]);
console.log(projects.title);
I have also tried using the for each element loop to no luck.
How would I grab the title of each element within this?
Share Improve this question edited Sep 24, 2018 at 8:15 Aleksey Solovey 4,1913 gold badges17 silver badges34 bronze badges asked Sep 24, 2018 at 8:10 J KaitJ Kait 151 gold badge1 silver badge5 bronze badges 3- post your code please. – Lia Commented Sep 24, 2018 at 8:11
-
Beware: this might be async. Can you please show the code which is populating the
projects
variable? – briosheje Commented Sep 24, 2018 at 8:16 - Unfortunately, this is a school project and deals with other students' data and so I do not wish to post my code. Sorry. – J Kait Commented Sep 24, 2018 at 18:26
2 Answers
Reset to default 5Try this :
console.log(projects[0].title);
First you need to access first array element and after the property
and for the foreach :
projects.forEach(projet=>console.log(projet.title));
Loop over your array with forEach and log the title of each objects.
const myArray = [{title: 'title1'}, {title: 'title2'}, {title: 'title3'}];
myArray.forEach(object => console.log(object.title));
You can find the documentation of forEach here.