在jQuery中,我可以这样做:
var books = [
{name: 'Book 1', author: 'John Wriggly', pages: 9},
{name: 'Book 2', author: 'James Wriggly', pages: 500},
{name: 'Book 3', author: 'Jacob Wriggly', pages: 52}
];
$(books).each(function(index, item){
console.log(item.name); // works!
});
var books = [
{name: 'Book 1', author: 'John Wriggly', pages: 9},
{name: 'Book 2', author: 'James Wriggly', pages: 500},
{name: 'Book 3', author: 'Jacob Wriggly', pages: 52}
];
books.forEach(function(index, item){
console.log(item.name); // undefined :(
})
所有属性都不起作用。作者、页数等。。。。我错过了什么?
编辑