For exmaple if I have a JavaScript Object like,
{
id: "234",
name: "shreyas",
active: "true"
}
How can I convert it to like this
{
id: 234,
name: "shreyas",
active: true
}
Basically removing "" (double quotes) from numbers and booleans.
I managed to remove booleans
let query = JSON.stringify(req.query);
query.replace(/"true"/g, `true`).replace(/"false"/g, `false`);
query = JSON.parse(query)
How can I do the same but with numbers?
What I tried so far:
const nums = query.match(/"\d+"/g);
nums?.forEach((num) => {
const newNum = parseInt(num)
query.replace(`${num}`, `'${newNum}'`);
});