1

toDoList 是一个数组,其中包含一些具有属性的对象

这个不行。它返回未定义。

const showToDo = toDoList.filter((todo)=>todo.isDone === true);
const showToDoTitle = showToDo.forEach(todo=>todo.title);

console.log(showToDoTitle);

这个有效

const showToDo = toDoList.filter((todo)=>todo.isDone === true);
showToDoTitle = showToDo.forEach(todo=>console.log(todo.title));
4

1 回答 1

1

.forEach不返回任何东西。

第二个有效,因为console.log().forEach函数中打印标题。如果你要console.log(showToDoTitle)在第二个例子中添加,你也会得到一个undefined打印的。

于 2018-12-25T16:13:30.440 回答