var email_recept=document.getElementsByClassName("email");
var counting_email_recept=email_recept.length;
var array_mail=[];
var myJSON=[];
for(var i=0;i<counting_email_recept;i++)
{
array_mail[i]=email_recept[i].value;
myJSON[i]=JSON.stringify({ email: array_mail[i] });
}
console.log(myJSON);
result :
["{"email":""}", "{"email":""}"]
i want to make like this : [{"email":""}, {"email":""}]
答案 0 :(得分:0)
你的问题有点含糊不清,但我想你可能想要......
var myJSON=[];
for(var i=0;i<counting_email_recept;i++) {
array_mail[i]=email_recept[i].value;
myJSON[i]={ email: array_mail[i] };
}
myJSON = JSON.stringify(myJSON);
// '[{"email":"a@a.a"},{"email":"b@b.b"}]'
答案 1 :(得分:0)
尝试使用此代码:
var email_recept=document.getElementsByClassName("email");
var counting_email_recept=email_recept.length;
var array_mail=[];
var myJSON=new array();
for(var i=0;i<counting_email_recept;i++)
{
array_mail[i]=email_recept[i].value;
myjson[i] = { email: array_mail[i] };
}
myJSON = JSON.stringify(myJSON);
console.log(myJSON);
你会获得所需的输出!