-1

How are you able to print all of the properties for objects in an array.

For example I have this array

const todo = [
  {
    text: "Water the plants",
    completed: true
  },
  {
    text: "Feed the dog",
    completed: false
  },
  {
    text: "Cook dinner",
    completed: true
  },
  {
    text: "Wash the dishes",
    completed: false
  },
  {
    text: "Clean the house",
    completed: false
  }
];

Am I able to print/access all of the text properties at the same time.

For example - if I use

console.log(todo.text)

I am given undefined? Are you not able to select all of these at the same time?

  • I would recommend reading up on [for..in loops](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in) and [indexed collections (arrays)](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Indexed_collections) – Jesse Feb 01 '20 at 01:49

1 Answers1

0

You need to loop through the array

const textArray = todo.map(item => item.text)
Michael
  • 878
  • 5
  • 17