Note that there are some explanatory texts on larger screens.

plurals
  1. POjavascript internet explorer array issues
    primarykey
    data
    text
    <p>I know that Internet Explorer &lt;9 has issues with Javascript arrays. I've tried <a href="http://code.google.com/p/ddr-ecma5/" rel="nofollow noreferrer">using</a> <a href="https://stackoverflow.com/a/6541169/2004825">stopgaps</a> but I can't for the life of me get this figured out.</p> <p>Basically, I have this code (pared way down):</p> <pre><code>YUI.add('query-params', function (Y) { Y.QueryParams = { /** Parses our query string and returns an object containing the k/v pairs passed in rules @method parse @param {String} query string to parse @param {RegExp} regex rules to compare our query string against @return {Object} returns an object containing the k/v pairs that match */ parse: function (qs, rules, params) { qs = qs.replace('?', ''); // remove ? from query string qs = qs.replace(/\+/g, ' '); var matches = rules.exec(qs); var defined_matches = Y.Array.filter(matches, function(m) { return ((typeof m != 'undefined') || ( m == true )); }); // rest of script omitted </code></pre> <p>And it is initialized as such:</p> <pre><code> &lt;script&gt; YUI({ modules: { 'query-params': { fullpath: './parse_search_terms.js' } }, onFailure: function (error) { console.log(JSON.stringify(error)); } }).use('node', 'console', 'query-params', function (Y) { var params = Y.QueryParams.parse(window.location.search, /(\w+)\s(\w+)\s(\w+)|(\w+)\s(\w+)/ig, ["firstName", "lastName", "state"]); var url = "url_to_send_to?firstName=" + params.firstName + "&amp;lastName=" + params.lastName + "&amp;state=" + params.state; var iframe = Y.Node.create('&lt;iframe&gt;&lt;/iframe&gt;').setAttrs({ src: url, frameBorder: 'no', height: 300, width: 800, scrolling: 'no' }); Y.one('#iframe').appendChild(iframe); }); </code></pre> <p>What I get in IE, Firefox and Chrome when I pass a query string like "q=john+smith+ca" and JSON.stringify the matches variable is this:</p> <pre><code>john smith ca,john,smith,ca,, </code></pre> <p>Firefox and Chrome do the right thing when I call Y.Array.filter on the array:</p> <pre><code>defined ["john","smith","ca"] </code></pre> <p>Internet Explorer 8 however:</p> <pre><code>defined ["john","smith","ca","",""] </code></pre> <p>So for some reason IE isn't filtering my array properly. I've tried all the aforementioned array shims and stopgaps but nothing seems to work. I would think that this would be pretty cross browser efficient since I'm using YUI3, but I'm stumped.</p> <p>Anyone have any ideas? Help much appreciated.</p>
    singulars
    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