Let category = "Baby Dress"
I want it to be trimed by spaces and text into lowercase. the output as "babydress". I used the following code. but it returns "baby dress".
category.trim(" ").toLowerCase()
I need to understand why it is not doing as I expected and what are the ways to do it.
It's not working as expected because .trim function is used to remove whitespace from both sides of the string, not from in-between.
You can use
category.toLowerCase().split(" ").join("")
Here I'm making the letters lower case, splitting them and then joining them.