Hi Friends đź‘‹,

Welcome To Infinitbility! ❤️

To each character of string in react native, use for...of loop, it will return each character one by one. You have to just use for...of loop on your string string.

Let’s see short example to use for loop on string to get each char.

for (let char of string) {
  console.log(char)
}

Today, I’m going to show you How do I get each character of string in react native, as above mentioned, I’m going to use the for...of loop method to get every char.

Let’s start today’s tutorial how do you get each character of string in react native?

React native get each character of string example

Here, we will take string state with some data and use for...of loop method to get each char of string.

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

export default function App() {
  const [str, setStr] = useState("Infinitbility");

  useEffect(() => {
    for (let char of str) {
      console.log(char);
    }
  }, []);

  return (
    <View>
      {str.split("").map((char) => {
        return <Text>{char}</Text>;
      })}
    </View>
  );
}

To get each character of the string to render components, I have used the split("") method to convert string to array and apply map() to iterate.

I hope it helps you, All the best đź‘Ť.

Output

React native get each character of string example
React native get each character of string example

Try it yourself