1

I am pulling information from a wordnik api, for the word of the day, I'm trying to get the array information, but the first part of the array works but the parts that are nested arrays within are appearing as object, object

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script>
  $.getJSON( "http://api.wordnik.com/v4/words.json/wordOfTheDay?api_key=a2a73e7b926c924fad7001ca3111acd55af2ffabf50eb4ae5", function( data ) {
    var items = [];

    $.each(data, function( key, val) {
      items.push( "<li id='" + key + "'><b>"+ key+ ":</b> " + val +  "</li>" );
    });

    $( "<ul/>", {
      "class": "my-new-list",
      html: items.join( "" )
    }).appendTo( "#james2" );
  });
</script>
2
  • My Codepen link is codepen.io/jamesfarrington/pen/yOMdJV Commented Mar 22, 2016 at 10:48
  • you have only iterate through one loop you have to do logic for nested loop to display all value Commented Mar 22, 2016 at 13:45

1 Answer 1

1

Try JSON.stringify() method on object.

$.each(data, function( key, val) {
    items.push( "<li id='" + key + "'><b>"+ key+ ":</b> " + JSON.stringify(val) +  "</li>" );
  });
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.