Enigma
Enigma

Reputation: 77

How to fetch objects of array one by one with for loop in react native

I've written for loop to fetch objects from array one by one, but the result fetched all of objects from loop and repeated those in one string.

Here is my code:

state = {
    b: ["A","B","C","D","E","F","G","H","I"]
}

b = () => {
    let d = [];
    for (var i =0; i<=this.state.b.length - 1; i++) {
        d.push(this.state.b[i])
    }
    return d;
};

I'm beginner in react native, how can I change this code to show object arrays like a list

Upvotes: 1

Views: 99

Answers (1)

Vivek Doshi
Vivek Doshi

Reputation: 58523

You can use ListView directly like this :

<ListView
    dataSource={this.state.b}
    renderRow={(rowData) => <Text>{rowData}</Text>}
/>

Upvotes: 2

Related Questions