I am attempting to insert a JSON object into another JSON object that is stored in local storage, but I am encountering an error saying "Object # has no method 'push'".
The JSON object stored in local storage is:
shops {
"c": [
{
"cliente_id": "12",
"cliente_name": "Vermut",
"cliente_url": "vermut",
"categoria_name": "Restaurantes",
"imagen": "1364.jpg",
"telefono": "456987123",
"descripcion": "El mejor sitio en el centro",
"latitud": "41.3865749",
"longitud": "2.1745545999999",
"direccion": "Carrera",
"porcentaje": "50",
"distancia": "0.0764"
},
{
"cliente_id": "92",
"cliente_name": "mexicano",
"cliente_url": "mexicano",
"categoria_name": "Restaurantes",
"imagen": "135.jpg",
"telefono": "",
"descripcion": "Comida a\r\n\r\nNuestros . \r\n",
"latitud": "3.9999",
"longitud": "6.9999",
"direccion": "Mexicana",
"porcentaje": "50",
"distancia": "0.771095"
}
]
}
This is the code where I am trying to merge the two JSON objects together. What could be causing the issue?
function addItem() {
// Retrieve the existing object
var oldCli = JSON.parse(localStorage.getItem('shops')) || [];
var newCli = {
"c": [
{
"cliente_id": "1",
"cliente_name": "Restaurante Quebracho",
"cliente_url": "restaurante-quebracho",
"categoria_name": "Restaurantes",
"imagen": "1355.jpg",
"telefono": "123654469",
"descripcion": "Quebrachos",
"latitud": "5.3456",
"longitud": "2.1264",
"direccion": "Ronda Quebracho",
"porcentaje": "25",
"distancia": "0.4273"
},
{
"cliente_id": "2",
"cliente_name": "Malinche",
"cliente_url": "disco-malinche",
"categoria_name": "Discotecas",
"imagen": "13493.png",
"telefono": "234567",
"descripcion": "Malinches.",
"latitud": "6.98765",
"longitud": "1.23456",
"direccion": "C Malinche 42",
"porcentaje": "30",
"distancia": "1.0994"
}
]
};
oldCli.push(newCli);
localStorage.setItem('shops', JSON.stringify(oldCli));
}