ObjectId.valueOf()

  • ObjectId.valueOf()
  • Returns the value of the ObjectId() as a lowercasehexadecimal string. This value is the str attribute of theObjectId() object.

Example

The following example calls the valueOf() method on an ObjectId():

  1. ObjectId("507c7f79bcf86cd7994f6c0e").valueOf()

This will return the following string:

  1. 507c7f79bcf86cd7994f6c0e

You can confirm the type of this object using the followingoperation:

  1. typeof ObjectId("507c7f79bcf86cd7994f6c0e").valueOf()