How to Get Last Character of String in React JS?
Oct 31, 2022 . Admin
Hello Friends,
This tutorial is focused on how to get last character of a string in react js. you will learn to get last character of the string in react js. We will use react js to get last character of the string. if you want to see an example of react js get last character of string example then you are a right place. follow the bellow step to get last character of string using react js.
in this example get last character of string in react js. I will step by step get string first character using str.charAt(str.length-1).
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 firstCharacter = str.charAt(str.length-1); return ( <div> <h1>{firstCharacter}</h1> </div> ); } const root = ReactDOM.createRoot(document.getElementById('root')); root.render(<App />);Run React JS App:
npm start
Output:
m
I hope it can help you...