JavaScript Displaying JSON data using Fetch API and map() in Javascript/Reactjs displaying json data in html,displaying json data in react

I have been trying to grab json data from an API and display it using the map() function. Unfortunately the API returns data in the format: { "type": ..., "value": ... }. The second object value contains an array with the data I want to access.

Is there a way I can access (or single out) JUST the second object in the API? and then I can run map() on it. See code below. This currently returns the error: this.state.jokes.map is not a function

P.S. the code works pefectly on APIs wrapped in an array e.g. http://jsonplaceholder.typicode.com/posts

class JokeList extends React.Component {

    constructor() {
        super();
        this.state = {jokes:[]};

    }

    componentDidMount() {
        fetch(`http://api.icndb.com/jokes`)
            .then(result => result.json())
            .then(jokes => this.setState({jokes}))
    }

    render () {

        return (
            <div> 
                {this.state.jokes.map(joke => 
                       <div key={joke.id}> {joke.joke} </div>)}
            </div>
        );
    }
}
Answer:1

Hi it is very simple question, but I didn't find the answer fit in my situation. In my jQuery dialog I have buttons which is update and close. User click 'update button' then on code behind I need ...

Hi it is very simple question, but I didn't find the answer fit in my situation. In my jQuery dialog I have buttons which is update and close. User click 'update button' then on code behind I need ...

I am attempting to pass 2 arrays to a function that filters through array 1 by array 2, then returns the filtered results. I am not understanding why I am getting the error: "Uncaught TypeError: arr2....

I am attempting to pass 2 arrays to a function that filters through array 1 by array 2, then returns the filtered results. I am not understanding why I am getting the error: "Uncaught TypeError: arr2....

  1. array some function example
  2. array some function in java
  3. typescript array some function
  4. js array some function
  5. array some arrow function
  6. php array some function
  7. angular array some function
  8. some array related functions in php
  9. array.some is not a function
  10. javascript array some arrow function

I have a 10 x 10 board and a button (in the demo given below I've minimized that to 3 x 3 ). When users click on the button the system generates a random number 1 to 9. document.getElementById(...

I have a 10 x 10 board and a button (in the demo given below I've minimized that to 3 x 3 ). When users click on the button the system generates a random number 1 to 9. document.getElementById(...

I am trying to add br tag between the text in react. can you guys tell me how to add it. I tried adding br tag... but if I add I get tag in the browser. providng my code below. can you guys tell me ...

I am trying to add br tag between the text in react. can you guys tell me how to add it. I tried adding br tag... but if I add I get tag in the browser. providng my code below. can you guys tell me ...