JavaScript How to initialise array in react-native using es6? initialise array react,initialize array react,initialize array react native

Hey guys i am trying to create empty array in react-native using es6. But while accessing it i get an error data not defined.

Here is the code snippet which i am using to initialise the array.

  constructor() {
    super();

    this.state = {
      search: "",
      data: []
    }
  }

Here is the code through which i am trying to populate the array and at the same time logging it

.then((responseData) => {
        this.setState({
          data: responseData.hits.hits.map(function(search){
            return{
              name: search._source.service_name
            }
          })
        })
        console.log(data);

i think so there is a problem in initialisation of array can anybody rectify it? thanks in advance

Answer:1

Your initializing of the array looks fine. You just can't access data like a local scoped variable. The data array in your example is a property/attribute of your state object.

So you need to access your data array like this: this.state.data

Answer:2

I have an array eg: a[3,4,5,6,7,8]. I want to remove all the element in one time and make array as an empty array. How to remove all the element of an array. My code var a = [2,3,4,5,6]; for(var i=...

I have an array eg: a[3,4,5,6,7,8]. I want to remove all the element in one time and make array as an empty array. How to remove all the element of an array. My code var a = [2,3,4,5,6]; for(var i=...

  1. remove elements from list python
  2. remove elements from array
  3. remove elements from a list
  4. remove elements from array java
  5. remove elements from array matlab
  6. remove elements from array python
  7. remove elements from vector c++
  8. remove elements from numpy array
  9. remove elements from dictionary python
  10. remove elements from vector r
  11. remove elements from list java
  12. remove elements from list r
  13. remove elements from array ruby
  14. remove elements from string python
  15. remove elements from set python
  16. remove elements from string
  17. remove elements from array c#
  18. remove elements from dom
  19. remove elements from list python by index
  20. remove elements from np array

I am trying to create a sidebar with CSS while also having a topbar in the same window. I have a <div id="topbar"> and a <div id="sidebar_left"> in my html file. In the topbar there are ...

I am trying to create a sidebar with CSS while also having a topbar in the same window. I have a <div id="topbar"> and a <div id="sidebar_left"> in my html file. In the topbar there are ...

  1. creating sidebar with bootstrap
  2. create sidebar with elementor
  3. create sidebar with bootstrap 4
  4. create sidebar with flexbox
  5. create sidebar with css
  6. create sidebar with js
  7. create sidebar with header
  8. creating sidebar in html
  9. creating sidebar in android studio
  10. creating sidebar in wordpress
  11. creating sidebar in angular
  12. creating sidebar in squarespace
  13. create sidebar in react
  14. create sidebar in word
  15. create sidebar in reactjs
  16. create sidebar in laravel
  17. create sidebar in react native
  18. create sidebar in angular 6
  19. create sidebar in shopify
  20. create sidebar in angular 7

I'm trying since 4 hours to arrange 4 div side by side vertically.Those div are also having 2 div inside it,for image and paragraph.I'm able to arrange the 4 image div next to each other but paragraph ...

I'm trying since 4 hours to arrange 4 div side by side vertically.Those div are also having 2 div inside it,for image and paragraph.I'm able to arrange the 4 image div next to each other but paragraph ...

I have a js file with one $(document).ready.. block. Since there are many anonymous functions inside this block, I've decided to move them and create functions. The problem is that when I've changed ...

I have a js file with one $(document).ready.. block. Since there are many anonymous functions inside this block, I've decided to move them and create functions. The problem is that when I've changed ...