Hello, in this jQuery video, I am going to show you how to use the trim method. So the trim method allows you to go a bit piece of string last spring in real life, that sort of thing that you try something with strings such as characters, and it gets rid of any, you know, whitespace. So spaces on the start and the DNI inside of it doesn't start at the end. So let's create a little button from what I can do purely in JavaScript. Before I do if I create a variable called epic string, instead on say, pizza and I want to know, okay, so now if I do console dot log see what we get. It's been printed there, but it's got those empty spaces before it, okay, so if you want to get rid of them, and one use case of this could be, you have some sort of input form, that's actually what I want to do as an extra task.
Use the skills that we've learned so far to, you know, have an input forms is basic HTML, get it. So using a selector in jQuery, get that string and then apply the trim method to it. So if you have an input form, maybe it's some sort of registration form on your new amazing Facebook 2.0 social media platform. You don't want Facebook to start and at the end of the day, the username and you might let them type it in, but you'll just get rid of it. anything in between. That's different by anything that starts at the end, you don't want it so to actually get rid of this Really simple.
All strings have a method called truth over do field doctrine or whatever the string is called. And I'm just printing out directly, I could pass it to another method, a custom method of the parameter, I could assign it to a variable, whatever you want. So if I reload, as you can see, pizza is the best and this no longer has the whitespace at the start and the end. So that's it for the trim method, really simple stuff. It removes whitespace from both sides of a string, then I can change the original string, so any white space in between is left the same simple stuff. If you have any questions, feel free to pop me a message.
And as usual, I look forward to seeing you in the next video.