我正在尝试创建名为client的对象。并放入一个数组。然后,读取第一个客户端的名称。
范例:
client1 {nom : "marco", prenom : "chedel", adresseMail : "[email protected]"};
并将此客户端放入波纹管之类的数组中。
listClients[client1]
我做了什么 :
var listClients = [];
var client1 = {nom : "chedel",prenom:"Marco",adresseMail:"[email protected]"};
listClients.push(client1);
var client2 = {nom : "De Almeida",prenom:"Jorge",adresseMail:"[email protected]"};
listClients.push(client2);
function afficheClients(tableau){
for (i=0;i<tableau.length;i++)
{
var c = tableau[i];
document.write(c[adresseMail]);
// This ^^ doesn't work, it says :adresseMail isn't definied in c
}
}
afficheClients(listClients);
最佳答案
您将adressMail
视为变量而不是字符串:
用
document.write(c["adresseMail"]);
关于javascript - JS:将对象放入数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19119901/