我需要有关将数组元素作为对象插入 Javascript 中的另一个数组的帮助。我有以下代码:
tableLength = 3;
nyCourt = [];
oldArr = [Buy, String, Question]
for (var t = 0; t < tableLength; t++) {
nyCourt.push({});
for (var i = 0; i < OldArr.length; i++) {
nyCourt.Title = OldArr[i] ;
}
};
代码不起作用,我希望以以下格式输出
[{Title:Buy },
{Title: String},
{Title: Question}]
但我得到的输出是这样的:
[{Title:Question },
{Title: Question},
{Title: Question}]