Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About Squarepusher

  • Rank
  • Birthday 07/29/1991

Previous Fields

  • Languages
    Some JavaScript
  1. Squarepusher

    Adding a "hashChange" event by "addEventListener"?

    I thought the opposite way and changed "c" to "C" because it also didn't work. Never mind, I found the error. Instead of "document.addEventListener" you must use window.addEventListener instead...
  2. I tried to add a "hashChange" event to the body element using the "onload" event, but nothing happens when the hash changes: document.addEventListener("hashChange", function() { alert(location.hash); }); But t works when I add onhashchange="alert(location.hash)" to the body element? Why?
  3. Squarepusher

    How to read names of arrays within an array?

    I don't know how to access these array... I want to change content on the page without loading a whole new page. Just like AJAX.
  4. Hello, I'm currently learning JavaScript and I plan to work a lot with arrays. I store all arrays in external files and use JSON to access them. Now I wanted to read the names of all arrays that are nested in one main array to create a navigation list but I don't know how to do that. This is an example of a JSON file I use: {"MainArray":[ {"SubArray1":[{ ... }] }, {"SubArray2":[{ ... }] }, {"SubArray3":[{ ... }] } ]} How do I get the names of all SubArrays? I tried this // arr is a JSON-parsed string function myFunction(arr) { var out = ""; var i; for(i = 0; i < arr.MainArray.length; i++) { out += arr.MainArray[i].toString() + '<br>'; } document.getElementById("aso").innerHTML = out; } but it only creates a list of "[object Object]" items. Should I create another JSON file where all array names are listed instead?