- 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)
505 Views
Use localStorage.setItem(“anyKeyName”, yourValue) to set the value in local storage and if you want to fetch value then you can use localStorage.getItem(“yourKeyName”)ExampleFollowing is the code − Live Demo Document var textBoxNameHTML = document.getElementById('txtName'); textBoxNameHTML.addEventListener('change', (e) => { localStorage.setItem("textBoxValue", e.target.value); }); To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output on console −Now, I ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
419 Views
Let’s say we have the following array −var studentDetails = [ [89, "John"], [78, "John"], [94, "John"], [47, "John"], [33, "John"] ];And we need to sort the array on the basis of the first item i.e. 89, 78, 94, etc. For this, use sort().ExampleFollowing is the code −var studentDetails = [ [89, "John"], [78, "John"], [94, "John"], [47, "John"], [33, "John"] ]; studentDetails.sort((first, second) => second[0] - first[0]) console.log(studentDetails);To run the above program, you need to use the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
685 Views
Let’s say the following is our array −var details = [ { studentName: "John", studentMarks: [78, 98] }, { studentName: "David", studentMarks: [87, 87] }, { studentName: "Bob", studentMarks: [48, 58] }, { studentName: "Sam", studentMarks: [98, 98] }, ]We need to remove the duplicate property value i.e. 87 is repeating above. We need to remove it.For this, use the concept of map().ExampleFollowing is the code −var details ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
214 Views
For this, use the addEventListener() with mousedown event.ExampleFollowing is the code − Document document.addEventListener("mousedown", function () { console.log("Mouse down event is happening"); }); To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output on console −When you click the mouse, the event will generate. The console output is shown below −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
At first, set a new Date in JavaScript −var dateValue = new Date("2021-01-12 10:10:20");Use new Date() along with setHours() and getHours() to add time.ExampleFollowing is the code −var dateValue = new Date("2021-01-12 10:10:20"); dateValue.setHours(dateValue.getHours() + 2); console.log("The date value is=" + dateValue.toString()); console.log("Only Hours value after incrementing=" + dateValue.getHours());To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo291.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo291.js The date value is=Tue Jan 12 2021 12:10:20 GMT+0530 (India Standard Time) Only Hours value after incrementing=12Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
271 Views
For this, use forEach() along with [] to an associative array.ExampleFollowing is the code −var result = {}; var names = ['John', 'David', 'Mike', 'Sam', 'Bob', 'Adam']; names.forEach((nameObject, counter) => { var generatedValues = { [nameObject]: counter }; Object.assign(result, generatedValues) }) console.log(result);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo290.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo290.js { John: 0, David: 1, Mike: 2, Sam: 3, Bob: 4, Adam: 5 }
![Yaswanth Varma](https://www.tutorialspoint.com/assets/profiles/511236/profile/60_1602256-1662106429.jpg)
543 Views
The innerHTML property of an element in JavaScript allows you to access or modify any HTML or XML markup that is there. Use the method insertAdjacentHTML () to insert HTML into the page as opposed to changing an element's content. In JavaScript to change a tag’s innerHTML based on their order can be done using document.querySelectorAll(). Let’s jump into the article to learn more about changing the tag’s innerHTML based on their order. Using document.querySelectorAll() The static NodeList returned by the Document function querySelectorAll() lists all of the document's elements that match the given set of selectors. Syntax Following is ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
Let’s say the following is our button −Press MeOn filling the below input field, the color of the above button should change −ExampleFollowing is the code − Live Demo Document UserName: Press Me function changeTheColorOfButtonDemo() { if (document.getElementById("changeColorDemo").value !== "") { document.getElementById("buttonDemo").style.background = "green"; } else { document.getElementById("buttonDemo").style.background = "skyblue"; } } To run ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
68 Views
If the const is used in a program, and if you try to reassign the value to const variable then an error will arise.Let’s say the following is our const variable −const result = (first, second) => first * second;Now, we will try to reassign a value to the const variable and an erro can be seen in the output.ExampleFollowing is the code −const result = (first, second) => first * second; result = first => first =first*10; console.log(result(10, 20)); To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo284.js.OutputThis will produce ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
3K+ Views
Let’s say we have the following sample video tag on a web page You cannot play video here...... To hide a video on a web page, use yourVariableName.style.display=’none’.ExampleFollowing is the code − Document .hideVideo { display: block; z-index: 999; margin-top: 10px; margin-left: 10px; } You cannot play video here...... var hideVideo = document.getElementsByClassName("hideVideo")[0]; hideVideo.style.display = ... Read More