I'm having display my arrays in html. I'm trying to achieve this in my Chrome Extension. I can see the Array perfectly in console.log, however not when trying to add it to the html dom:
/* 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);
The above code should show all the Array information in the #anydiv correct?
However, the only information I get is: [object Object],[object Object]
I've also tried .toString() which didn't help.
I'm not sure if JSON.stringify could help me and how I would implement it if it does?
I've been stumped on this for hours, so much research and now I feel like my brain is scrambled and I'm missing something obvious? Any help would be hugely welcome. Please :-)
Have you already tried the following?
$('#anydiv').text(JSON.stringify(wsitemadded));
If it does not work well, you should show what you saw in console for console.log(wsitemadded).