D
D
Dmitry Anatolyevich2020-07-15 18:21:42
JavaScript
Dmitry Anatolyevich, 2020-07-15 18:21:42

How to correctly generate JSON code to display the result of a loop?

Hello! Who can tell me how to correctly form the JS code of the FOR cycle so that the output is just such a text in its pure form.

[{
"text": "{{status 1}}",
"callback_data": "{{tid 1}}"
}] ,
[{
"text": "{{status 2}}",
"callback_data": " {{tid 2}}"
}],

Code itself:

var code = [];
for (var i = 1; i < 3; i++){
code[i] = 
           [{
                    "text": "{{status [i]}}",
                    "callback_data": "{{tid [i]}}"
            }],   
}
var myJSON = JSON.stringify(code);
resolve(myJSON);


I can’t remove the comma at the end of the loop, it needs to be escaped somehow or something done with it so that it does not affect the operation of the loop.
I'm making a telegram bot on FLOWXO and I need to display info through a piece of code in a loop

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question