JavaScript alphabets and spaces validation

Spaces and Letters or alphabets-only validation in JavaScript is used to make sure that all the characters entered in the specified field must be any character from A-Z or a-z or white space. Regular Expression: /^[a-z][a-z\s]*$/ Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function lettersAndSpaceCheck(name) { var regEx = /^[a-z][a-z\s]*$/; if(name.value.match(regEx)) { return true; } … Read more

JavaScript alphabets validation

Letters or alphabets-only validation in JavaScript is used to make sure that all the characters entered in the specified field must be any character from A-Z or a-z. Regular Expression: /^[A-Za-z]+$/ Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function lettersOnlyCheck(name) { var regEx = /^[A-Za-z]+$/; if(name.value.match(regEx)) { return true; } else { alert(“Please enter letters … Read more

not empty validation JavaScript JS

Not empty or blank field validation is used to check whether anything is entered in a given field or not. It will check for null and zero-length strings. Example: <!DOCTYPE html> <html lang=”en”> <head> <script> function notEmptyCheck(name) { if (name.value.length == 0) { alert(“Name can not be empty.”); return false; } return true; } </script> … Read more

JavaScript Map values() method

The JavaScript map values() method is used to retrieve an object of Map iterator that contains the values for each element. Syntax: mapObj.values() Return: An object of Map iterator. Example: <!DOCTYPE html> <html> <body> <script> var map=new Map(); map.set(‘a’,”GOOD MORNING”); map.set(‘b’,”GOOD AFTERNOON”); map.set(‘c’,”GOOD EVENING”); map.set(‘d’,”GOOD NIGHT”); var itr= map.keys(); for(i=0;i<map.size;i++){ document.writeln(itr.next().value+”<br>”); } </script> </body> </html>

JavaScript Map set() method

The JavaScript map set() method adds a new or modifies the already existing key-value pairs to Map object. Syntax: mapObj.set(key,value) Parameters: key: It represents the key of the newly added map object. value: It represents the value of the newly added map object. Return: Updated map object. Example: <!DOCTYPE html> <html> <body> <script> var map=new … Read more

JavaScript Map keys() method

The JavaScript map keys() method is used to retrieve an object of the Map iterator that contains the keys for each element. Syntax: mapObj.keys() Return: An object of Map iterator. Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(‘a’,”GOOD MORNING”); hello.set(‘b’,”GOOD AFTERNOON”); hello.set(‘c’,”GOOD EVENING”); hello.set(‘d’,”GOOD NIGHT”); var array= hello.keys(); document.writeln(array.next().value+”<br>”); document.writeln(array.next().value+”<br>”); document.writeln(array.next().value+”<br>”); document.writeln(array.next().value); </script> … Read more

JavaScript Map has() method

The JavaScript map has() method is used to indicate whether the map object contains the specified key element. Syntax: mapObj.has(key) Parameters: key: It represents the specific key that has to be searched. Return: Returns true if the specified key is present in the map otherwise returns false. Example: <!DOCTYPE html> <html> <body> <script> var hello=new … Read more

JavaScript Map get() method

The JavaScript map get() method is used to retrieve the value of a specified key. Syntax: mapObj.get(key) Parameters: key: It represents the specific key corresponding to which value has to be retrieved. Return: The value corresponds to a specific key. Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(1,”GOOD MORNING”); hello.set(2,”GOOD AFTERNOON”); hello.set(3,”GOOD EVENING”); … Read more

JavaScript Map forEach() method

The JavaScript map forEach() method is used to execute the specified function once for each key/value pair. Syntax: mapObj.forEach(callback) Parameters: callback: It refers to the function which has to be executed. Example: <!DOCTYPE html> <html> <body> <script> var hello=new Map(); hello.set(1,”GOOD MORNING”); hello.set(2,”GOOD AFTERNOON”); hello.set(3,”GOOD EVENING”); hello.set(4,”GOOD NIGHT”); document.writeln(“Elements are:”+”<br>”); function print(elements) { document.writeln(elements+”<br>”); } … Read more

Map entries() method JavaScript

The JavaScript map entries() method is used to retrieve an object of Map iterator that contains the key-value pair for each element. Note: The iterator object keeps the insertion order of map elements. Syntax: mapObj.entries() Return: An object of Map iterator Example: <!DOCTYPE html> <html> <body> <script> var bday=new Date(“November 16, 1994 21:10:10”); document.writeln(bday.toDateString()); </script> … Read more