草庐IT

stringObjectIdArray

全部标签

javascript - 将字符串数组转换为对象 Id 数组

我有一个字符串数组letstringObjectIdArray=['fssdlfsd343','43434234242','342424242']我想通过使用mongoose类型将字符串数组更改为对象Id数组,但它没有用。它仅适用于字符串而不适用于数组类型。letobjectIdArray=mongoose.Types.ObjectId(stringObjectIdArray)//abovewillgiveerror在这种情况下有什么办法可以帮助我吗?非常感谢你帮助我! 最佳答案 使用Array.prototype.map()在数组