我正在使用UnderscoreJs。考慮以下代碼:下劃線_.each和_.map之間的區別是什麼?
var docs = [
{name : 'Anders', niche : 'Web Development'},
{name : 'Johnny', niche : 'Design'},
{name : 'Eric', niche : 'PhotoShop'}
];
var newDocs = _.map(docs, function (doc){
delete doc.niche;
return doc;
});
如果我使用.each
或.map
這裏沒關係。結果是完全一樣的。
在上述情況下兩者的區別究竟是什麼?
什麼庫,下劃線? – Mritunjay 2014-08-28 15:48:45
閱讀[the manpage](http://documentcloud.github.io/underscore/docs/underscore.html#section-13),查找起來並不難。 – Nit 2014-08-28 15:50:11
'_.each()'*迭代*,'_.map()'* projects *,即使用您指定的函數來構建新元素,從作爲輸入傳遞的那個構建一個新數組。 – 2014-08-28 15:50:22