I have the following function that creates an object:
function createDebit(name, value, paymentDate){
var debit = {"type": name,"value": value,"PaymentDate": paymentDate};
return debit;
}
This object that it returns I will add. on another object with this function:
var newDebit = createDebit("GVT", "200.00", "10/10/2010");
addValue("Bradesco", "arrayDebits", newDebit);
function addValue(where, element, content){
var execute;
var local = localStorage.getItem(where);
local = JSON.parse(local);
var verifyType = "$.isArray(local."+element+")";
// Verifica se o elemento do objeto destino é um array
if(eval(verifyType)){
// Caso seja, add o conteudo via push
if(typeof(content) == "string"){
execute = "local."+element+".push('"+content+"')";
}else if(typeof(content) == "object"){
execute = "local."+element+".push("+content+")";
}
}else{
execute = "local."+element+"='"+content+"'";
}
console.log(execute);
console.log("Execute now...");
eval(execute);
console.log("Done Execute");
storage_save(where, local);
}
But it always gives error:
jQuery.Deferred exception: Unexpected identifier SyntaxError: Unexpected identifier
If I try to pass the object via STRING:
function createDebit(name, value, paymentDate){
var debit = '{"type":' + name + ',"value": ' + value + ',"PaymentDate": ' + paymentDate + '}';
return debit;
}
{"nameCategory": "Bradesco", "arrayDebits": ["{\" type \ ": \" GVT \ ", \" value \
How can I actually save the object inside the array that is inside another object?