因此,我在我的mongoose模式中有一個查詢,它在resultArray中顯示這個資訊
。[
{ scholarship_type: 'Archer Achiever Scholarship' },
{ scholarship_type: 'Star Scholarship' },
{ scholarship_type: 'Star Scholarship' },
{ scholarship_type: 'Archer Achiever Scholarship' },
{ scholarship_type: 'Star Scholarship' },
{ scholarship_type: 'Archer Achiever Scholarship' }.
]
我想把這個陣列轉換為一個子串,它是
"Archer Achiever Scholarship, Star Scholarship, Star Scholarship, Archer Achiever Scholarship, Star Scholarship, Archer Achiever Scholarship"
提前感謝您!
uj5u.com熱心網友回復:
用js做這件事的一個簡單方法。 通過使用.map(),我們遍歷這些物件,并回傳獎學金型別屬性。這給了我們一個包含獎學金型別屬性的字串陣列。
const scholarshipObjects = [{ scholarship_type: 'Archer Achiever Scholarship' },/*...*/]
const scholarshipsList = scholarshipObjects.map(
(scholarship) => scholarship.scholarship_type)
);
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/319844.html
標籤:
上一篇:如何使用NestJs在jest測驗案例中使用UserDocument/UserModel?
下一篇:創建資料模型的正確方法是什么?
