1

The Array

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?

3
  • post your code please. Commented Sep 24, 2018 at 8:11
  • Beware: this might be async. Can you please show the code which is populating the projects variable? 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. Commented Sep 24, 2018 at 18:26

2 Answers 2

5

Try 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));
Sign up to request clarification or add additional context in comments.

Comments

1

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.