Javascript Archive

difference between .map() vs .forEach() in javascript / nodejs

If you’re new to JavaScript, you may be wondering what the difference is between using a classic for loop versus using the forEach() method on arrays. Here in this post we will try to understand which loop is better to use in javascript / nodejs. In JavaScript, you’ve probably come across two seemingly similar Array methods: and Array.prototype.forEach(). so what is

Validate multiple email id’s using JavaScript

In this post, we will see how to validate multiple email id's with comma/semicolon separator in text box using JavaScript. function validateEmail(field) { var regex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,5}$/; return (regex.test(field)) ? true : false; } function validateMultipleEmailsCommaSeparated(emailcntl, seperator) { var value = emailcntl.value; if (value != '') { var result = value.split(seperator); for (var i =

Allow only numbers to be typed in a textbox HTML

Here we will see how to allow only numeric  or number to be types in any html textbox. This will be useful for phone number field, pincode or for only numeric authentication purpose. To achieve this you could subscribe for the onkeypress event: HTML TEXTBOX <input type="text" class="textfield" value="" id="phone_number" name="phone_number" onkeypress="return hasNumber(event)" /> Now