-2

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.

5
  • Use the ObjectID.toString() method. Commented Jun 28, 2022 at 11:02
  • How does function/class ObjectId look like? Commented Jun 28, 2022 at 11:03
  • Welcome to Stack Overflow! Please take the tour if you haven't already (you get a badge!) and read through the help center, in particular How do I ask a good question? Aside from the issue of lack of detail, your best bet here is to do your research, search for related topics on SO and elsewhere, and give it a go. If you get stuck and can't get unstuck after doing more research and searching, post a minimal reproducible example showing your attempt and say specifically where you're stuck. People will be glad to help. Commented Jun 28, 2022 at 11:04
  • Is this supposed to be a MongoDb ObjectId ...? You should at least properly tag the question then. And then: developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/… Commented Jun 28, 2022 at 11:05
  • Also, is ObjectId the one from MongoDB? If so, this is a duplicate of this question. Please search thoroughly before posting. More about searching here. Commented Jun 28, 2022 at 11:06

2 Answers 2

0

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

Sign up to request clarification or add additional context in comments.

Comments

-1

i think ObjectId is custom constractor if it is you have write method return that id and you can call that method where you need

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.