0

I am pulling data from Mysql to React native. As you can see, the output of the data I have captured is in the array. How can I pull Array data? With the code below, I can pull the data into an array. For example, I want to extract the new_image variable from the array.

  getBusinessNewsData() {
fetch('...').then((response) => response.json())
    .then((findresponse)=>{
  var newSearch = findresponse.new_image;
        console.log(newSearch)

      this.setState({
        data:newSearch,
      })

    })
[
       {
          "id":"..",
          "new_date":"...",
          "new_title":"...",
          "new_slug":"...",
          "new_url":"",
          "new_image":"...",
          "new_fixed":"..."
       }
    ]

2 Answers 2

1

Map on the response and extract new_image

const result = findResponse.map((d) => d.new_image);

Then you can set result in component internal state.

Sign up to request clarification or add additional context in comments.

Comments

0

If the console.log(newSearch) gives you the array above and you want to have the new_image property then you can set a state like this.setState({ newImage: newSearch[0].new_image })

By doing so this.state.newImage would be the value from the array.

2 Comments

But there it only shoots the first array. I also want to pull news_image's assigned values ​​in 1.2.3.
For that you can use the FlatList Component React Native provides. It takes the Data as an Array and gives you back a component for every entry (object) inside the array.

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.