Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON.stringify not converting array.object correctly
    primarykey
    data
    text
    <p>I'm having a problem with JSON.stringify</p> <p>I'm trying to pull all the meta tags out of the page and pass them to a firefox worker file to work through them and to return back an object.</p> <p>So my code previously worked when I didn't have a worker running the issue has only cropped up when I have moved to using worker file (for reasons I can't go into I need to use a worker!)</p> <p>So previously I would get all the meta tags using </p> <pre><code>var metas = document.getElementsByTagName("meta"); </code></pre> <p>then I could loop through the metas object by using</p> <pre><code>for (var index in metas){ var currentMeta = metas[index]; //(and so on, this code worked perfectly) </code></pre> <p>The problem occurs when I move to the external worker file scenario. What happens is I pull the meta tags out as normal, and then I use JSON.stringify to something that I can push to the worker.</p> <p>After all that intro blab, here is the root of my problem: Take for example that I land on a page with the following code within the html</p> <pre><code>&lt;meta content="width=1024" name="viewport"&gt; &lt;meta charset="UTF-8"&gt; &lt;meta content="Mozilla Hacks – the Web developer blog" name="title"&gt; </code></pre> <p>If I run the following code I get an array </p> <pre><code>var metas = document.getElementsByTagName("meta"); </code></pre> <p>returns an array 3 elements</p> <pre><code>[meta, meta, meta] </code></pre> <p>If I stringify it using:</p> <pre><code>var jsonMetas = JSON.stringify(metas); </code></pre> <p>I would expect to jsonMetas to hold something like:</p> <pre><code>{"0":{"content":"width=1024","name":"viewport"},"1":{"charset":"UTF-8"},"2":{"content":"Mozilla Hacks - the web developer blog","name":"title"} } </code></pre> <p>However when I look at the jsonMetas object I see this returned:</p> <pre><code>{"0":{"constructor":{}},"1":{"constructor":{}},"2":{"constructor":{}}} </code></pre> <p>Huh?????</p> <p>I'm not that good at JavaScript, so could you please explaining (in very small words :) ) what is going on?</p> <p>Why does the stringify call return the unusually structured object? What am I doing wrong?</p> <p>Thanks in advance for your answers.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload