JavaScript数组forEach

时间:2017-05-09 20:43:29

标签: javascript arrays foreach

我在数组中有一个名为blogs的数组存在这些对象:

var blogs = new mongoose.Schema({
title: String,
image: String,
body: String,
author: {
  id: {
     type: mongoose.Schema.Types.ObjectId,
     ref: "User"
  },
  username: String
 },comments: [
  {
     type: mongoose.Schema.Types.ObjectId,
     ref: "Comment"
  }
 ],
 created: {type: Date, default: Date.now}
});

我想创建一个仅显示具有相同用户名示例admin的博客的forEach。 我的forEach代码

blogs.forEach(function(blog){
// prints blogs
}

0 个答案:

没有答案