In my JavaScript code, I am trying to retrieve a variable value enclosed in double quotes. The value is obtained from an input field, but it comes wrapped in single quotes.
I have already attempted the following code:
let id=document.querySelector("#v_id"); //v_id represents the ID of the input field
let stringID= id.value;
var vObj = {id:stringID};
However, the result appears like this { id: '1'}
with single quotes around the value.
This format does not work when using the value in a JSON object.
I require the result to be formatted as { id: "1"}
with double quotes enclosing the value.
Your valuable response would be highly appreciated.