Phi*_*ter 5 javascript arrays jquery sweetalert
我有一个返回数组的函数,如下所示:
但我正在尝试填充SweetAlert2对话框.
正如文档所示,所需的输入将如下所示
inputOptions: {
'SRB': 'Serbia',
'UKR': 'Ukraine',
'HRV': 'Croatia'
},
Run Code Online (Sandbox Code Playgroud)
考虑到密钥与值相同,我怎样才能将我的数组转换为所需的格式?
所以,这样的结果将是结果:
{
'aaa123': 'aaa123',
'Açucena': 'Açucena',
'Braúnas': 'Braúnas',
[...]
}
Run Code Online (Sandbox Code Playgroud)
我试过了JSON.stringify,但输出不是我需要的:
"[[" AAA123" , "Açucena", "布劳纳斯","C.Fabriciano " "格格", "gegeq2", "伊帕廷加", "若阿内夏", "梅斯基塔", "Rodoviário", "睾丸中", "teste2", "TIMOTEO", "Tomatoentro", "TS"]]"
Ami*_*mit 17
这可以通过简单的reduce调用完成:
// Demo data
var source = ['someValue1', 'someValue2', 'someValue3', 'other4', 'other5'];
// This is the "conversion" part
var obj = source.reduce(function(o, val) { o[val] = val; return o; }, {});
// Demo output
document.write(JSON.stringify(obj));Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
19485 次 |
| 最近记录: |