簡體   English   中英

在node.js中,有沒有一種方法可以將對象數組轉換為具有特定屬性的數組?

[英]Is there a way to convert an object array to an array of certain property, in node.js?

我的標記方案:

{  
_id:xxxx,  
name:String,  
}

假設我有兩個文檔:

{_id:xxxx,  name:a}  
{_id:xxxx,  name:b}

我想獲取所有標簽名稱並以數組形式返回:[a,b]。
有簡單的方法嗎? 我在用貓鼬。

如果要獲取所有實例,請在構建Tag模型之后,在模型上使用find()方法:

    Tag.find({}, function(err, tags) {
         if(!err){
        console.log(tags);
      }

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM