The map function is used to show a list of elements in an array. It can be used in React Native like the following example:

BY Best Interview Question ON 17 Mar 2020

Example

import React, { Component } from "react";
import { Text, View } from "react-native";

export default class mapFunction extends Component {
constructor(props) {
super(props);
this.state = {
array: [
{
title: "example title 1",
subtitle: "example subtitle 1"
},
{
title: "example title 2",
subtitle: "example subtitle 2"
},
{
title: "example title 3",
subtitle: "example subtitle 3"
}
]
};
}

list = () => {
return this.state.array.map(element => {
return (
<View style={{ margin: 10 }}>
<Text>{element.title}</Text>
<Text>{element.subtitle}</Text>
</View>
);
});
};

render() {
return <View>{this.list()}</View>;
}
}