I have a table a such
Env | depot | articles |
---|---|---|
100 | AAA | Capacitor |
100 | AbA | Diode |
100 | AAA | cable |
100 | AbA | mike |
100 | ABC | modem |
900 |
I’m getting the dropdown values using JavaScript as such :
let selectElementEnv = document.getElementById('env');
let optionNamesEnv = [...selectElementEnv.options].map(o => o.text);
console.log(optionNamesEnv );
Console output is
[ '100', '900']
To get the Depot values
let selectElementDepot = document.getElementById('Depot');
let optionNamesDepot = [...selectElementDepot.options].map(o => o.text);
console.log(optionNamesDepot );
Console output
[ 'AAA', 'AbA', 'AAA', 'AbA', 'ABC', '']
To get the Articles values
let selectElementArticles = document.getElementById('Articles');
let optionNamesArticles = [...selectElementArticles .options].map(o => o.text);
console.log(optionNamesArticles );
Console output
[ 'Capacitor', 'Diode', 'mike', 'modem', '']
How could i transform this outputs to get this json format ?
var myjson = [
{
"env": "100 ",
"depot": " AAA",
"articles": "Capacitor"
}, {
"env": "100 ",
"depot": "AbA",
"articles": "Diode"
}, {
"env": "100 ",
"depot": " AAA",
"articles": "cable"
},{
"env": "100 ",
"depot": "AbA",
"articles": "mike"
}, {
"env": "100 ",
"depot": "ABC",
"articles": "modem"
}, {
"env": "900",
"depot": "",
"articles": ""
}
}];