This snippet capitalizes the first letter of a string.
Miscellaneous
Redirect to a specified URL
Use Window.location.href or Window.location.replace() to redirect to url. Pass a second argument to simulate a link click (true – default) or an HTTP redirect (false).
Get an attribute on an element
Use Element.getAttribute() to get an attribute (including data attributes) on an element.
Optional Chaining to Prevent Crashes
If you access an undefined property, an error is produced. This is where optional chaining comes to the rescue.
Return all elements in an array except for the first one
Return Array.prototype.slice(1) if Array.prototype.length is more than 1, otherwise, return the whole array.
Highlight an element when dragging a file over it
We will highlight the element when user drags a file over it. For example, the element will have a dashed border which can be simulated by a CSS class.
Remove Duplicates From an Array
In JavaScript, Set is a collection that lets you store only unique values. This means any duplicated values are removed.
How to loop through arrays and array-like objects in JavaScript
Here is how to loop through arrays and array-like objects using JavaScript.
How to Get the Query String in JavaScript
When you’re working with JavaScript, sometimes you need to access query string parameters in your script.
Check if an Object Is Empty
ere are some different methods that you could use to check if an object is empty in modern browsers that support the ES5 edition of JavaScript.