How to Remove Last Character of String in React JS?
Nov 01, 2022 . Admin
Hello Friends,
This tutorial is focused on how to remove the last character of a string in react js. We will use remove last character of string in react js. This article will give you a simple example of react js remove last character of a string. if you want to see an example of react js remove last character of string example then you are the right place.
In this example remove last character of string in react js. I will step by step remove the last character using slice().
So, let's start following example:
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 React from 'react'; import ReactDOM from 'react-dom/client'; function App(){ const str = 'Mywebtuts.com'; const newStr = str.slice(0, -1); return ( <div> <h1>{newStr}</h1> </div> ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />);Run React JS App:
npm start
Output:
Mywebtuts.co
I hope it can help you...