我有這段代碼。 我想以與陣列的其它物體內部的值動態地設置對象使用JavaScript對象內的數組並動態使用數組值
var object1 = {repetidos : {}};
var object2 = {nombre: 'Example', precio: 'Example 2', etc...};
//Object with the array
var carga = {
repetidos : ['nombre','precio']
}
// custom function to set objects... I don't want to return nothing
cargaDatos(object1,object2,carga);
// Here is the function that i'm trying to code
cargaDatos = function(object1,object2,carga){
// what can i do here?. I have tried to use for loops
for(var key in carga){
for(var key2 in key){
//Here I have tried many things
}
}
}
//////////////////////////////////////////////////////////
// I want set something like this inside the function
object1.repetidos.nombre = object2.nombre; // nombre is variable
object1.repetidos.precio = object2.precio; // precio is variable
etc ....
怎麼辦與變量值設定的對象,如以上?
謝謝加比工作完美! – ns777 2014-11-21 13:09:01