简体   繁体   中英

How to convert Array of ObjectID to Array of string?

I have a array of objectID like this-

 [
    new ObjectId("62bab157e769a7dda09ec63f"),
    new ObjectId("62bab15ce769a7dda09ec64a"),
    new ObjectId("62bab164e769a7dda09ec657")
 ]

Now I need to get result like this-

[
  '62bab157e769a7dda09ec63f',
  '62bab15ce769a7dda09ec64a',
  '62bab164e769a7dda09ec657'
]

I need the conversion function in one line just. Please help me.

 let object = [ new Object("62bab157e769a7dda09ec63f"), new Object("62bab15ce769a7dda09ec64a"), new Object("62bab164e769a7dda09ec657") ]; let objectString = object.toString(); let stringArray = objectString.split(","); console.log(stringArray);

我认为 ObjectId 是自定义构造函数,如果你有 write 方法返回那个 id 并且你可以在你需要的地方调用那个方法

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM