Converting a string to lowercase in React is done using JavaScript’s built-in toLowerCase()
method. Here’s how you can achieve this:
import React from 'react';
function StringToLowercase() {
const originalString = "Hello World";
const lowercaseString = originalString.toLowerCase();
return (
<div>
<p>Original String: {originalString}</p>
<p>Lowercase String: {lowercaseString}</p>
</div>
);
}
export default StringToLowercase;
In this example, the StringToLowercase
component converts the originalString
to lowercase using the toLowerCase()
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 lowercase versions of it.
Keep in mind that toLowerCase()
does not modify the original string; instead, it returns a new string with all characters converted to lowercase.