0

I am Relatively a new programmer. and I am trying to retrieve a specific id value from a promise. I want a specific value inside this promise, device.deviceId , but I am not able to take it out separately and use it in the code. Tried to use a global variable and assign the value to global variable but since it is asynchronous, not able to update the value. can someone help?

let dev


const videoSelecter = navigator.mediaDevices.enumerateDevices()
.then(devices => {

devices.forEach(function(device) {

if (device.kind == "videoinput" && device.label=="Doccamera (2b19:0200)") {  
    dev=device.deviceId
   console.log("updated device ID", dev)
   return dev  
}
});
return dev
})

dev variable gets me the id but is not able to use it outside this block.

videoSelecter returns value

> Promise {<pending>}
> __proto__: Promise [[PromiseStatus]]: "resolved" [[PromiseValue]]: "14aa34325245"

I am trying to access the value in [[PromiseValue]]

Harry
  • 389
  • 1
  • 6
  • 18

0 Answers0