I try to use the bootbox.js library. The question is how to dynamically create function parameters. For example, how to form an array of inputOptions options based on some of its own array in a loop. Well, for example, there is json

[ {"id":"2","language":"ENG","language_full":"Английский"}, {"id":"1","language":"RU","language_full":"Русский"} ]

And how to get something from it suitable for insertion into inputOptions (see below)?

  { text: 'Русский', value: 1, }, { text: 'Английский', value: 2, }, 

Here is an example of the function of the bootbox.js library

 bootbox.prompt({ title: "This is a prompt with select!", inputType: 'select', inputOptions: [ { text: 'Choose one...', value: '', }, { text: 'Choice One', value: '1', }, { text: 'Choice Two', value: '2', }, { text: 'Choice Three', value: '3', } ], callback: function (result) { console.log(result); } }); 

    1 answer 1

    Not sure I understood the question, but probably something like this:

     var json = [ {"id":"2","language":"ENG","language_full":"Английский"}, {"id":"1","language":"RU","language_full":"Русский"} ], options = []; for(let i = 0; i < json.length; i++) { options.push({ text: json[i].language_full, value: json[i].id }); } console.log(options);