How to Convert String to Array in React JS?
Nov 29, 2022 . Admin
Hello Friends,
In this example, I will show you convert string to array in react js. you'll learn string to array convert. We will use convert string to an array using Split().
If you want to convert string to array in react js. Then I will show you a step-by-step example of how to convert string to array in react js. So, let's see the below steps:
Step 1: Create React JS AppIn this step, open your terminal and execute the following command on your terminal to create a new react app:
npx create-react-app reactjs-my-exampleStep 2: Create index.js file src/index.js
import {useState} from 'react'; import ReactDOM from 'react-dom'; export default function App() { // create string const myString = 'Mywebtuts'; // get output string to array console.log(myString.split('')); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(Run React JS App:);
npm startOutput:
['M', 'y', 'w', 'e', 'b', 't', 'u', 't', 's']
I hope it can help you...