Tengo que mostrar mis matrices en html . Estoy tratando de lograr esto en mi extensión de Chrome. Puedo ver el Array perfectamente en console.log, sin embargo, no cuando intento agregarlo al dom html:
/* Creates the array for chrome extension */ chrome.storage.local.get({wsitemadded: []}, function (result) { var wsitemadded = result.wsitemadded; /* Collects the desired data */ var witenumfetch = $('#wsitemnumber').text(); var wspecialtitlefetch = $('#title').val(); var wspecialprice = $('.mwsb-wsp').text(); var wspecialprevprice = $('.mwsb-prevprice').text(); var wspecialdeldate = $('.mwsb-deldate').text(); var wspecialimg = $('#postad-img-0 div img').attr('src'); /* Pushes the Data into the Arrays (Key/Value) */ wsitemadded.push({WSItemNumber: witenumfetch, WSTitle: wspecialtitlefetch, WSImage: wspecialimg, WSPrice: wspecialprice, WSPrevPrice: wspecialprevprice, WSDELDate: wspecialdeldate}); chrome.storage.local.set({ wsitemadded: wsitemadded }); }); /* Displays current stored Arrays */ setTimeout( function(){ chrome.storage.local.get({wsitemadded: []}, function (result) { var wsitemadded = result.wsitemadded; console.log(wsitemadded); /* Displays the Arrays correctly in Chrome Dev console */ $('#anydiv').text(wsitemadded); /* Should display all the Array data */ }); }, 300); El código anterior debería mostrar toda la información de la matriz en #anydiv , ¿correcto?
Sin embargo, la única información que obtengo es: [object Object],[object Object]
También probé .toString() que no ayudó.
No estoy seguro de si JSON.stringify podría ayudarme y cómo lo implementaría si lo hace.
He estado perplejo en esto durante horas, tanta investigación y ahora siento que mi cerebro está revuelto y me estoy perdiendo algo obvio. Cualquier ayuda sería muy bienvenida. Por favor :-)
¿Ya has probado lo siguiente?
$('#anydiv').text(JSON.stringify(wsitemadded));Si no funciona bien, debe mostrar lo que vio en la consola para console.log (wsitemadded).