Arrays data being retrieved and set by Chrome Extension are visible in the console but not appearing in the HTML

Having trouble displaying my arrays in HTML. I'm attempting to do this within a Chrome Extension. While I can view the array perfectly in console.log, I'm encountering issues when trying to add it to the HTML DOM:

   /* Generating the array for the Chrome extension */
        chrome.storage.local.get({wsitemad: []}, function (result) {
          var wsitemadded = result.wsitemadded;
        /* Gathering the required 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'); 
          /* Adding the Data to the Arrays (Key/Value pairs) */
          wsitemadded.push({WSItemNumber: witenumfetch, WSTitle: wspecialtitlefetch, WSImage: wspecialimg, WSPrice: wspecialprice, WSPrevPrice: wspecialprevprice, WSDELDate: wspecialdeldate});
          
          chrome.storage.local.set({ wsitemadded: wsitemadded });
        });
       /* Showing the current stored Arrays */
        setTimeout(
          function(){
          chrome.storage.local.get({wsitemadded: []}, function (result) {
            var wsitemadded = result.wsitemadded;
            console.log(wsitemadded); /* Shows the Arrays correctly in the Chrome Dev console */
            $('#anydiv').text(wsitemadded); /* Should display all the Array data */
          });
         }, 300);
    

The code above is meant to display all the Array information in #anydiv, right?

However, all I see is: [object Object],[object Object]

I've attempted using .toString() but that didn't provide a solution.

Not sure if JSON.stringify could assist and how I'd incorporate it if necessary?

I've been stuck on this dilemma for hours, done extensive research, and now I feel like I'm overlooking something obvious? Any assistance would be greatly appreciated. Please :-)

Answer №1

Did you give this a shot already?

$('#anydiv').text(JSON.stringify(wsitemadded));

If it's not functioning properly, make sure to display the output from console.log(wsitemadded).

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can we include identical item names within a single JavaScript object?

My attempt at achieving the desired result involves creating an object like this: var obj = {id: id, items: "asdf", items: "sdff", test: varTest}; However, I face a challenge where I need to dynamically add two elements with the same name 'items&apo ...

Fade in images using jQuery

I am having issues with fading in and out images using jQuery, it doesn't seem to be working as expected. I think there might be something crucial that I am missing. Take a look at the script below: var count = 1; setInterval(function() { ...

Using an AJAX post request will result in receiving an HTML element, especially when an attachment is included with Paperclip

I've created an innovative application where users can share their stories through ajax submissions and engage with other readers by commenting on the stories using ajax as well. The technology stack I'm working with includes Rails 3.0.3, ruby 1. ...

Error message encountered in node-schedule: Unable to read undefined property upon job restart

Using node-schedule, I have successfully scheduled jobs on my node server by pushing them into an array like this: jobs.push(schedule.scheduleJob(date, () => end_auction(req.body.item.url))); Everything is working as expected. When the designated date ...

use javascript or jquery to conceal the textbox control

Looking to conceal a textbox control using javascript or jquery. I attempted the following code: document.getElementsByName('Custom_Field_Custom1').style.display="none"; Unfortunately, I received an error in the java console: document.getEle ...

Creating an npm module using an external JavaScript API script

I am currently in the process of creating an npm package using code from this repository. In my possession is the "minified" js file called http_www.webglearth.com_v2_api.js, which is automatically downloaded by IntelliJ when the <script src=""> tag ...

When debugging in ASP MVC4, JavaScript will only evaluate HiddenFor once you've paused to inspect it

Struggling with evaluating a hidden field in JavaScript (ASP MVC4). I've set up a model in my View with a hidden input for one of the properties. @Html.HiddenFor(mdl => mdl.FilterByUser, new { @id = "filterByUserId" }) Within my Helper, I have a ...

How can I set up automatic language selection for Google Translate's menu indexing feature?

My goal is to implement an automatic page translation feature using Google Translate's Library. I have been following the instructions provided in this link: The issue lies in the code snippet below, where the select menu creation works fine, but acc ...

Substituting a constant string for a value in a JSON object

In a JSON file, there is content with a "pos" value that needs to be replaced with a constant like NNNN. This value varies in length each time. { "qual_table": "TKGGU1.TCUSTORD", "op_type": "INSERT", "op_t ...

What is the best way to reset an a-select component in Ant Design Vue?

I need to programmatically reset the selection in my a-select component after a specific event is triggered. Here's an example of my a-select code snippet: <a-select style="marginTop: 8px;width: 20%" @change="onChanged" > ...

Comparing Perl multithreading with JSON manipulation

I encountered an issue with the program below, resulting in the following error message: JSON text must be an object or array (but found number, string, true, false or null, use allow_nonref to allow this) at json_test.pl line 10. The program runs withou ...

Eliminating redundant items from an array

I am working with two numpy arrays: [ 2.09588161 2.34243927 2.45505059 3.61549894 6.42506932 8.52095092 5.76933731 6.03952746 4.30033044 3.77862927 3.73546847 5.40022069 8.52095092 10.61683253 7.75964201 8.01668568 6.174 ...

Is there a method to establish varied usage permissions for a single page without any tracking?

I am puzzled by how a solution could create something like this. My goal is to have a webpage displaying 2 squares on a large screen. There will be 2 users, each needing access to write in their own square only on this page. <div class="square1"> ...

Parsing Json data into structured objects

Although this question has been asked numerous times, I have attempted various solutions without success. I have experimented with Json.Net, JavaScriptSerializer, and others... Below is a snippet of the JSON data I am looking to deserialize. It should be ...

Retrieving data from the firebase database by filtering based on the child's specific value

Looking at the firebase database, I can see that only the 'name' field is available. Now, I am trying to retrieve the 'quantity' value associated with that specific 'name'. Can someone provide me with a sample firebase query i ...

Error: Encountered an unexpected token while trying to parse multiple form functions

I recently added the following submission function to my .js file: $( "form" ).on( "submit", function( event ) { event.preventDefault(); var data = $( this ).serialize(); $.ajax({ type: "POST", url: "content/rev/a_sub ...

Transferring variables from the $(document).ready(function(){}) to the $(window).load(function(){} allows for seamless and

Just think about if I successfully create percent_pass at the time of document.ready, how can I transfer that variable to window.load? $(document).ready(function() { jQuery(function() { var ques_count = $('.question-body').length; va ...

Ways to retrieve the returned value from the JS FETCH API outside of its scope

As a beginner in Typescript React and the Ionic framework, I am trying to use the JS FETCH API to fetch data from a third-party source. However, I am struggling to access this fetched data outside of the fetch function. If anyone could provide some guidan ...

What is the best way to trigger a function to return a property value within the same React component file when using the map function?

Currently, I am dealing with a unique data structure that resembles the following: allPersons:[ { discoveriesByType:[ {type:'car',pending:0,confirmed:10, discoveries:[{data...}]}, {type:'truck',pending:1,confirmed:25 ...

Challenge with scroll function in Internet Explorer JavaScript

Here is the code snippet I am working with: var lastScrollTop = 0; window.addEventListener("scroll", function(){ var st = window.pageYOffset || document.documentElement.scrollTop; if (st > lastScrollTop){ $('.sticky').addClass('insi ...