I’m trying to have the key of the object not be surrounded by single quotes.
let arr= [2, 3, 4, 11];
let myObj={};
myObj[arr[2]]=true;
console.log(myObj);
The above code outputs the result { ‘4’: true }
How do I remove the single quotes around 4 and have it display as { 4: true }
>Solution :
You can do it like so:
const arr = [2, 3, 4, 11];
const myObj = {};
myObj[arr[2]] = true;
const str = JSON.stringify(myObj);
console.log(str.replace(/[",']/g, ''));