Data viz projects

Data viz projects


Hi - I am using Atom to build my first data viz project. (Will move it over to codepen before submitting).

I am trying to get to the point where I am console.logging the exact data that I want (so I know that I am accessing it appropriately) before I then go about building the HTML + SVG around that data.

I think I am getting lost in the [array[array: {obj...} ]] weeds, so to speak.

What I want right now is to get the “year” value from the returned JSON data:

        "value":"Population, total"
        "value":"Arab World"

And this is my code so far. I have 2 questions within the code. Thanks.

<!DOCTYPE html>
<html lang = "en">
      <script src = ""></script>

          req=new XMLHttpRequest();

            json = json.filter(function(val) {
              return (val[0]);                 //:question:**isn't filter supposed to return ONLY the values that pass...? This is returning the opposite...??**

            console.log(json[0]); //:question:If val[0] gives me an array with 50 elements, why won't json[0] = val[0][0]...?

            // document.getElementsByClassName('message')[0].innerHTML=json;

      <button id="getMessage">
        Get Message

      <p class="message">
        The message will go here


What are you filtering for? The function within the filter either returns true to keep the current item, or false to drop it. Right now, for each element of the array you’re saying “if the first element of this sub-array is ANY non-false value, return true.” Is that your intent?


Thanks Tobias! That was helpful. I was thinking that the code meant, “does the first element of this sub array exist”.