Nilesh
Nilesh

Reputation: 618

how to manipulate a string variable in react js

I have one label for which value is coming from an array. I want to use that name for giving id ti my label. Below is the code for that.

<label htmlFor={name}><b>{ name }</b> </label>

How can I covert it to lower case and remove the spaces in between of it so that I can have proper id in html. I am looking somewhat like below.

<label htmlFor={name}.trim().toLowerCase()><b>{ name }</b> </label>

Upvotes: 0

Views: 265

Answers (1)

Quentin
Quentin

Reputation: 943569

Regular JavaScript expressions go between { and } in JSX, not just variable names.

htmlFor={ name.trim().toLowerCase() }

Note that trim only removes spaces at the start and end of a string, not in the middle.

Upvotes: 2

Related Questions