How to change array to string in react js?

Hi Friends 👋,

Welcome To aGuideHub! ❤️

Today, I am going to show you. how to change array to string in react js with code example.

In this article, we will create a simple change array to string in React.js just like you would create in a normal HTML project.

we have an array of objects stored in react state object we are going to convert the array to a string

In the render method, using the map method to create an iterated array of objects and a result object

Let’s look at the following example to understand how it basically works:

APP.js

import React from "react";

import "./App.css";

const App = () => {
  const itemList = ["Item1", "Item2", "Item3", "Item4", "Item5"];

  // Generate JSX code for Display each item
  const renderList = itemList.map((item, index) => 
                               <div key={index}>{item}</div>
                             );
  return (
    <div className="app">
		{itemList.toString()}
      <div>The List contains:</div>
      {renderList}
    </div>
  );
}

export default App;

Step to Run Application: Run the application using the following command from the root directory of the project:

npm start

Output: Now open your browser and go to http://localhost:3000/, you will see the following output:

Check the output of the above code example.

React, Click

All the best 👍

Premium Content

You can get all the below premium content directly in your mail when you subscribe us

Books

Portfolio Template

View | Get Source Code

Cheat Sheets

Cheat Sheets Books are basically Important useful notes which we use in our day-to-day life.

I'm working on some more Cheat Sheets book on Jquery, TypeScript, React js and for other languages. I will send it once it's completed.

Related Posts