React Native Create and Show Array Elements in Text using MAP

Array is used to store multiple values in a single object in react native. Array can hold infinite values(According to your requirement) in a single variable. So in this tutorial we would going to Create and Show Array Elements in Text component using MAP function. So let’s get started .

Topics cover in this tutorial :

  1. Array Declaration.
  2. Inserting values in Array using Manually method.
  3. Showing Array Values in Text Component one by one like ListView.
  4. Adding onPress-onClick method on Array Item to get its value on click event.

Contents in this project Create and Show Array Elements in Text using MAP in React Native :

1. Import StyleSheet, Text, View and Alert component in your project.

2. Create a function named as SampleFunction() with item argument inside it. This function is used to show the selected array element on Button onPress .

3. Create a Local Array inside render’s block named as SampleNameArray. Now we would manually insert some values in array. I am inserting my class mates name, You can insert any data according to your requirement.

4. Now we would make a Root View in render’s return block.

5. Finally we would print the Array values in Text Component using MAP function.

item : Represents the each item of array.

key : Represents the Item index value like 0, 1, 2.

6. Create Style for Root View and Text component.

7. Complete source code for App.js File :

Screenshot in Android device :


Show Array ElementsScreenshot in iOS device :