D
D
Dima2018-08-21 12:01:22
JavaScript
Dima, 2018-08-21 12:01:22

How to make numbers remain without quotes?

Hello. Do not get angry)
There is such a pen
as a result, the data from the forms goes to the json format

{
    "ItemToOrders": [{
        "Qty": "1",
        "FrameStyle": "2"
    }],
    "cotact": {
        "city": "уу",
        "country": "уу"
    }
}

how to make it so that there are no "quotes" around the numbers
, like this
{
    "ItemToOrders": [{
        "Qty": 1,
        "FrameStyle": 2
    }],
    "cotact": {
        "city": "уу",
        "country": "уу"
    }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Buravtsov, 2018-08-21
Dolgoter @SpiderPigAndCat

You can use a regular:

const regex = /"(\d+)"/g;
const subst = `$1`;

const result = foo.replace(regex, subst);

console.log(result);

E
eternalfire, 2018-08-21
@eternalfire

in a loop through the ItemToOrders array, bring its values ​​to a number

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question