<p>Original String: {originalString}</p> " />

PASSWORD RESET

Your destination for complete Tech news

How to convert a string to uppercase in React JS?

1.26K 0
< 1 min read

Converting a string to uppercase in React is done using JavaScript’s built-in toUpperCase() method. Here’s how you can achieve this:

import React from 'react';

function StringToUppercase() {
  const originalString = "Hello World";
  const uppercaseString = originalString.toUpperCase();

  return (
    <div>
      <p>Original String: {originalString}</p>
      <p>Uppercase String: {uppercaseString}</p>
    </div>
  );
}

export default StringToUppercase;

In this example, the StringToUppercase component converts the originalString to uppercase using the toUpperCase() method. The converted string is then displayed in the output.

Replace "Hello World" with your own string, and the component will display both the original and uppercase versions of it.

Keep in mind that toUpperCase() does not modify the original string; instead, it returns a new string with all characters converted to uppercase.

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.