How to Convert string into Array in React Native?

Sep 14, 2022 . Admin

Here, I will show you React Native Convert String to Array. We will use How to covert String into array in React Native. We will use react native converting array into string. it's simple example of convert json string to array in react native. So, let's follow few step to create example of How to convert string value in array and split and make two values in react native.

In this example,We will convert to string to array in rreact native.you can easy and simply split to use in rect app.then display to array mobile app use JSON.stringify in react native.let's below example.

Step 1: Download Project

In the first step run the following command to create a project.

expo init ExampleApp
Step 2: App.js

In this step, You will open the App.js file and put the code.

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

const App = () => {

  const string = "This is String";
  const myArray = string.split(" ");

  return (
    <View style={styles.container}>
      <Text style={styles.text}>{ JSON.stringify(myArray) }</Text>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "space-around",
    alignItems: "center",
  },

  text: {
    fontSize: 25,
  },

});

export default App;
Step 3: Run Project

In the last step run your project using the below command.

expo start

You can QR code scan in Expo Go Application on mobile.

Output:

It will help you...

#React Native