
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10483 Articles for Web Development

578 Views
Let’s say the following is our radio button group − Gender: Male Female To check a radio in radio group, you need to set checked property to true in JavaScript. Following is the code −Example Live Demo Document Gender: Male Female var tagValues = document.getElementsByTagName('input'); for (const obj of tagValues) { if (obj.value === 'Male'){ obj.checked = true; } } To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output −

408 Views
For this, you can use the concept of modular operator along with divide. Following is the code −Examplevar divideInteger = function(value, divide) { var num; var modular = value % divide; if(modular == 0){ num = value/divide; sumOfDivideParts = Array(divide).fill(num); } else { num = (value-modular)/divide; sumOfDivideParts = Array(divide).fill(num); for(i=0;i node demo169.js [ 6, 6, 6, 6, 6, 6, 7, 7 ]

90 Views
Let’s say the following is our object −var lastName ={ "John":"Smith", "David":"Miller", "Bob":"Taylor" }Following is our array −var firstName=[ "Bob", "John", "David" ]Display resultant array based on the object’s order determined by the first array, use map(). Following is the code −Examplevar firstName=[ "Bob", "John", "David" ] var lastName ={ "John":"Smith", "David":"Miller", "Bob":"Taylor" } var values = firstName.map(getValues => lastName[getValues]); console.log(values);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo168.js. This will produce the following output −PS C:\Users\Amit\javascript-code> node ... Read More

433 Views
To make first letter of a string uppercase, use toUpperCase() in JavaScript. With that, we will use charAt(0) since we need to only capitalize the 1st letter.Examplefunction replaceWithTheCapitalLetter(values){ return values.charAt(0).toUpperCase() + values.slice(1); } var word="javascript" console.log(replaceWithTheCapitalLetter(word));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo167.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo167.js Javascript

237 Views
To avoid using variable name as a literal, use square brackets. Following is the code −Examplevar name = "David" var putTheAllData = [] putTheAllData.push( { name: "The name is name will remain same" } ) putTheAllData.push( { [name]: "The name is David will be changed [name]"} ) console.log(putTheAllData);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo166.js. This will produce the following output −PS C:\Users\Amit\javascript-code> node demo166.js [ { name: 'The name is name will remain same' }, { David: 'The name is David will be changed [name]' } ]

943 Views
For this, use push() along with forEach(). Following is the code −Examplevar details = [{name:"John"},{name:"David"}] var addObject = ["Mike","Sam"]; addObject.forEach( obj1 => { if(!details.find( obj2 => obj2===obj1 )) details.push({name:obj1}) }) console.log(details);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo165.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo165.js [ { name: 'John' }, { name: 'David' }, { name: 'Mike' }, { name: 'Sam' } ]

675 Views
Let’s say the following are our strings with commas −"My Favorite subject is, " "My Favorite subject is, and teacher name is Adam Smith" "My Favorite subject is, and got the marks 89"To replace commas, use replace and in that, use Regular Expression. Following is the code −Exampleconst makingRegularExpression = /, (?=[^, ]*$)/; replaceComma("My Favorite subject is, "); replaceComma("My Favorite subject is, and teacher name is Adam Smith"); replaceComma("My Favorite subject is, and got the marks 89"); function replaceComma(values){ console.log(values, " ==== replaced by JavaScript ==== ", values.replace(ma kingRegularExpression, " JavaScript")); }To run the above program, you need ... Read More

2K+ Views
Let’s say the following is our string with name −var studentFullName="John Smith";Use split() to split the first name and last name. Following is the code −Examplevar studentFullName="John Smith"; var details=[] var details=studentFullName.split(' '); console.log("StudentFirstName="+details[0]) console.log("StudentLastName="+details[1]);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo163.js. This will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo163.js StudentFirstName=John StudentLastName=Smith

1K+ Views
The primitive data types are number, string, boolean, float etc. The non-primitive data types (Reference Type) are Array, Object etc.Examplevar number=10; var stringValue="John"; var booleanValue=true; var obj={}; var newArray=new Array(); console.log("The data type is="+typeof number); console.log("The data type is="+typeof stringValue); console.log("The data type is="+typeof booleanValue); console.log("The data type is="+typeof obj); console.log("The data type is="+typeof newArray);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo162.js. This will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo162.js The data type is=number The data type is=string The data type is=boolean The data type is=object The ... Read More

26K+ Views
For ENTER key press event, you can call a function on −onkeypress=”yourFunctionName”Use the ENTER’s keycode 13.Example Live Demo Document function enterKeyPressed(event) { if (event.keyCode == 13) { console.log("Enter key is pressed"); return true; } else { return false; } } To run the above program, save the file name "anyName.html (index.html)" and right click on the file. Select the option "Open with Live Server" in VS Code editor.OutputThis will produce the following output −On pressing ENTER key, the following output is visible on console −