How to Escape Special Characters in JavaScript

How to Escape Special Characters in JavaScript

To escape special characters in JavaScript, use the encodeURIComponent() method. The encodeURIComponent() is a built-in JavaScript function that encodes a URI by replacing each instance of certain characters with one, two, three, or four escape sequences representing the UTF-8 encoding of the character. Syntax encodeURIComponent(uriComponent); Parameters uri – We can pass any data types like … Read more

How to Remove First Character from String in Javascript

How to Remove First Character from String in Javascript

To remove the first character from the string in JavaScript, use the slice() method. The string.slice() is a built-in JavaScript method that extracts a part of a string. The slice() method returns the extracted part in a new string. The slice() method does not change the original string. Syntax string.slice(startIndex, endIndex); Parameters start index –  It is … Read more

How to Get Time in 12 Hour Format in Javascript

How to Get Time in 12 Hour Format in Javascript

To get time in 12-hour format in Javascript, use the toLocaleString() method. The toLocaleString() is a built-in JavaScript method that returns a string with a language-sensitive representation of a date. Syntax toLocaleString(locales,options); Parameters It takes two parameters: locales and options. But these are also optional. Locales –  We can specify that en-us, etc. Options –  We … Read more