【发布时间】:2021-12-05 19:29:18
【问题描述】:
我创建了一个数组,我必须向用户询问新数据,然后我必须将此新信息添加到我的原始数组中,但是当我尝试添加由用户。
如何将新歌曲(歌曲名称和持续时间)添加到我的原始数组中?
这是我的代码:
let discos = [];
let disco1 = {
discoName: 'Disco Name ',
band: 'Catupecumachu',
code: 1,
songs: [
{
'songName': 'song1',
'duration': 200,
},
{
'songName': 'song2',
'duration': 180,
},
{
'songName': 'song3',
'duration': 90,
},
],
};
let disco2 = {
discoName: 'Disco Name',
band: 'U2',
code: 2,
songs: [
{
'songName': 'song1',
'duration': 200,
},
{
'songName': 'song2',
'duration': 180,
},
{
'songName': 'song3',
'duration': 90,
},
],
};
let discoUser = {
discoName: '',
band: '',
code: '',
songs: [
{
'songName': '',
'duration': '',
},
],
};
discos.push(disco1, disco2, discoUser);
do{
discoUser['discoName'] = prompt('discoName');
discoUser['band'] = prompt('band');
discoUser['code'] = prompt('code');
}while(confirm('Continue?'));
【问题讨论】:
标签: javascript arrays push prompt