- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- 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 9313 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
441 Views
Let’s first set a button − Call Above, we have set a function under “onclick” to call two other functions −function callTwoOtherFunctions(){ fun1(); fun2(); }In this way, work around the fun1() and fun2() as in the complete code below −Example Live Demo Document Call function callTwoOtherFunctions(){ fun1(); fun2(); } function fun1(){ console.log("Function1()") } function fun2(){ console.log("Function2()") } To run the above program, save the file name “anyName.html(index.html)” ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
582 Views
To check for valid date format, match the date with −const dateFormat = /^\d{4}\-\d{2}\-\d{2}$/;Example Live Demo Document .check-valid-date { border: 1px solid red; } const dateFormat = /^\d{4}\-\d{2}\-\d{2}$/; document.getElementById("check-valid-date").addEventListener("change", checkingForValidDate); function checkingForValidDate() { console.log(this.value, dateFormat.test(this.value)); this.classList.toggle('check-valid-date', dateFormat.test(this.value)); } 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 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
339 Views
To modify string, you can use toLowerCase() as well as toUpperCase(). Let’s say the following is our string −var sentence = "tHIS iS tHE JavaScript pROGRAM";To modify and display in proper case, the code is as follows −Examplevar sentence = "tHIS iS tHE JavaScript pROGRAM"; function modifyStringWithMultipleMethods(sentence) { return sentence.charAt(0).toUpperCase() + sentence.slice(1).toLowerCase(); } console.log(modifyStringWithMultipleMethods(sentence));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo51.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo51.js This is the JavaScript programRead More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
To remove text, use the concept of remove(). Use filter to get the content not inside element tag.Let’s say the following is our HTML −Demo Program This is also Demo ProgramAnd we have to remove “This is also Demo Program” since it is not under element tag. For that, the compete code is as follows using filter() and remove() −Example Live Demo Document Demo Program This is also Demo Program $('body').contents().filter(function(){ return this.nodeType != 1; }).remove(); To run the above program, save the file ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
824 Views
To loop through all DOM elements on a page, use document.getElementsByTagName(‘*’). Loop through its length and display the result in console as in the below code −var tags = document.getElementsByTagName("*"); for (var i=0, max=tags.length; i < max; i++) { console.log(tags[i]); }Example Live Demo Document Demo Enter the name: Save var tags = document.getElementsByTagName("*"); for (var i=0, max=tags.length; i < max; i++) { console.log(tags[i]); } To run the above program, save the file name “anyName.html(index.html)” and right click on the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
193 Views
Let’s say the following is our nested array −const arrayObject = [ [ { Name: "John" }, { countryName: "US" } ], [ { subjectName: "JavaScript" }, { teacherName: "Mike" } ] ];To transform nested array into normal array, use the concept of flat() as in the below code −Exampleconst arrayObject = [ [ { Name: "John" }, { countryName: "US" } ], [ { subjectName: "JavaScript" }, { teacherName: "Mike" } ] ]; const output = arrayObject.flat(); console.log(output);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo50.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo50.js [ { Name: 'John' }, { countryName: 'US' }, { subjectName: 'JavaScript' }, { teacherName: 'Mike' } ]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
To get the value of H1 to JavaScript variable, you can use −document.getElementById().innerHTML.Let’s say the following is our H1 heading − This is the demo program of JavaScript ........Now, let’s get the H1 value using the below code −Example Live Demo Document This is the demo program of JavaScript ........ var data=document.getElementById('demo').innerHTML; console.log("The data is="+data); 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 ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
68 Views
Let’s say we have records with BOTID and Name of assigned users −let objectArray = [ { BOTID: "56", Name: "John" }, { BOTID: "57", Name: "David" }, { BOTID: "58", Name: "Sam"}, { BOTID: "59", Name: "Mike" }, { BOTID: "60", Name: "Bob" } ];We know the array starts from index 0. If you want to access the first element from the above array, use the below syntax −var anyVariableName=yourArrayObjectName[index].yourFieldName;Examplelet objectArray = [ { BOTID: "56", Name: "John" }, { BOTID: "57", Name: "David" }, { BOTID: "58", Name: "Sam"}, ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
273 Views
To add a newline in Unordered List, use the document.querySelector().append(). Following is the code −Example Live Demo Document h1{ font-size: 2.50rem; } h2, label{ font-size: 1.50rem; } Adding Name Demo Enter The Name: Save List Of Name const buttonName = document.querySelector('.btnName') const addName = e => { let nameTxt = document.querySelector('.txtName'), name = nameTxt.value.trim() if (name) { let tagLi = ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
233 Views
At first, set the keys −const name = ['Name1', 'Name2'];Now, map keys to the same value using for loop as in the below code −Exampleconst name = ['Name1', 'Name2']; const keyValueObject = {}; for (const k of name){ keyValueObject[k] = 'John'; } console.log(keyValueObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo48.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo48.js { Name1: 'John', Name2: 'John' }