0
ich ein Objekt haben:Wie fügt dynamisch zu einem JavaScript-Objekt
var someObject={};
und ich habe eine Funktion, die auf das Objekt fügt hinzu:
function add(id, firstName){
//stuff that makes sure id and firstName are correct format and stuff and say if firstName is john and id is I23423
someObject.id=firstName;
}
aber immer ausgegeben als
someObject{
id="john"
}
aber ich möchte die ID, was auch immer der Benutzer die ID eingibt, so wird die Ausgabe
seinsomeObject{
I23423="John"
}
Was kann ich hinzufügen/ändern?
http://stackoverflow.com/questions/695050/how-do-i-add-a-property-to-a-javascript-object-using-a-variable- wie der Name – epascarello
meinst du 'someObject [id] = firstName;'? – bansi