5 Useful JavaScript/jQuery codes and techniques with examples – Must use


JavaScript is one of the most powerful programming languages in website development. It has the power to controls the frontend parts through event handlers and provides easy inbuild methods that make life easier on the backend part also. It is used almost everywhere.

Here are some advantages of JS:

  1. JavaScript is relatively simple to learn and implement.
  2. Client-side JavaScript is very fast.


  1. The main problem in JavaScript is that the code is always visible to everyone anyone can view JavaScript code.
  2. If the error occurs in JavaScript, it can stop rendering the whole website.

check here to see more pros and cons.

To make the easiness in code, jQuery is introduced which is a JavaScript library designed to simplify HTML DOM tree traversal and manipulation, as well as event handling, CSS animation, and Ajax.

In this article, we are talking about some useful techniques of JavaScript jQuery that everyone should know to strongly improve the user experience.

1️⃣ Use of forEach() loop to make the code neat and smart

The forEach() method calls a function once for each element in an array, in ascending order. Here is the example

forEach() loop that will also skip the empty index value, for example

So, forEach() is useful to iterate over all array items, without breaking, involving simultaneously some side-effects. Its first argument is the callback function, which is invoked for every item in the array with 3 arguments: item, index, and the array itself.

Or else you can check array methods also.

2️⃣ Get the Text of the selected item from <select> tag

I think most people know how to get the value of a selected item from the dropdown list, but I am asking about the Text of that selected item. There is a very simple way to do this:

3️⃣ How to get the day name, date, and more from DateTime Picker in jQuery

Today, Most websites are using the DateTimePicker plugin of jquery. It’s very easy to integrate with the project by just providing the CDN links. Why we should use this? Because it has customized properties, so that, we can add anything that we want.

We were having inbuild methods to find out the date, year, time, and so on… But how to use this? I describe you one by one

That’s all about DateTimePicker. ✌

4️⃣ Want to generate a random SecureToken number of a particular length?

Need to save any file like images, Docx, pdf, etc.. in a secure way. Like if you saved the file with the real name creates ambiguity between the user’s data. If it is good to use some secure way to save any files then? Yes, there are a lot of ways or methods to do so… But I have taken a very simple and very effective method to give the random name to the files.

Use this secure token id to save in a secure way.🙌

We used this secureToken concept in one of the Related Post – Easy way to Upload the File/Image in Laravel using AJAX jQuery with example

5️⃣ Check validation of any input type using jQuery

We can validate the input by using the regex patterns in <input> tag

In this way, we can validate any input type by using the checkValidity() method. Simple as that 😉

So, these are some snippets, and techniques of Javascript / jQuery which you would like to use. I hope you enjoyed the article and if you found this useful then share this among your friends or on social media.

If you have any queries please feel free to post them in the comments section or anything that you wanted to ask through mail contact.


Related Article

[7] Advanced and Useful Linux – Ubuntu Commands How to revert or undo last commit in Git? Explain For, While, Do-While Loops in JS and more Setup AWS CLI on MAC, Windows, and Linux Introduction to Comparison and Logical Operators in JS Difference between AWS, AZURE, and GCP Cloud Conditional Statement in JS – with examples