Javascript 如何访问数组中对象的属性
如何打印数组中对象的所有属性 例如,我有这个数组Javascript 如何访问数组中对象的属性,javascript,arrays,javascript-objects,Javascript,Arrays,Javascript Objects,如何打印数组中对象的所有属性 例如,我有这个数组 const todo = [ { text: "Water the plants", completed: true }, { text: "Feed the dog", completed: false }, { text: "Cook dinner", completed: true }, { text: "Wash the dishes", comp
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
}
];
我是否能够同时打印/访问所有文本属性
例如,如果我使用
console.log(todo.text)
我被赋予了未定义的含义?您不能同时选择所有这些吗?您需要在阵列中循环
const textArray = todo.map(item => item.text)
我建议你仔细阅读一下