这是我的代码:
function Todo(id, task, who, dueDate) {
this.id = id;
this.task = task;
this.who = who;
this.dueDate = dueDate;
this.done = false;
}
var todos = new Array();
window.onload = init;
function init() {
var submitButton = document.getElementById("submit");
submitButton.onclick = getFormData;
var searchButton = document.getElementById("button");
searchButton.onclick = search;
}
//function creates objects
function search() {
for (var i = 0; i < todos.length; i++) {
var todoObj = todos[i].who;
console.log(todoObj[0]);
}
}
我创建的两个对象的值分别是“jane”和“scott”。这在控制台中返回的首先是“j”,然后是“s”。所以它正在访问两个对象中的第一个字母。当我只输入 console.log(todoObj); 它返回“jane”和“scott”。我需要能够单独访问每个名称。我怎样才能做到这一点?