我有一个提交多个数据的 javascript 表单集,如果我得到所有的发布数据,我有类似下面的内容
firstname1: "John",
lastname1: "Doe",
firstname2: "Mary",
lastname2: "Allinson",
firstname3: "David"
lastname3: "Mark",
eventDesctiption: "Lorem Ipsum...",
eventDate: "Lorem Ipsum..."
在本例中,我有一个隐藏字段,其中包含提交的姓名数量;它的 3. 我希望能够循环遍历名称并将它们放入对象数组中,然后再发布到 API,我希望能够实现以下目标
{
eventDesctiption: "Lorem Ipsum...",
eventDate: "Lorem Ipsum...",
people: [
{firstname: "John", lastname: "Doe"},
{firstname: "Mary", lastname: "Allinson"},
{firstname: "David", lastname: "Mark"},
]
}
我尝试了下面的方法,但它似乎将索引与值连接起来,这不是我想要的
peopleArray = new Array();
for(var i=1; i<=no_of_ben; i++){
var peopleObject = {};
peopleObject.firstname = data.firstname + 'i';
peopleObject.lastname = data.lastname + 'i';
peopleArray.push(peopleObject);
}
如何在不连接索引的情况下执行此操作
一只斗牛犬
喵喔喔
慕雪6442864
相关分类