- 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 9312 Articles for Object Oriented Programming
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
257 Views
Let’s say the following is our array object −var arrayObject = [ "John", "David", "Mike" ]You can use length property to set the length to 0 and clear memoryThe syntax is as follows to clear memory −yourArrayObjectName.length=0; // To clear memory yourArrayObjectName.length=4; // To allocate memoryOutputThis will produce the following output on console −var arrayObject = [ "John", "David", "Mike" ] arrayObject.length = 0; console.log(arrayObject); arrayObject.length = 5; for (var i = 0; i < arrayObject.length; i++) ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
860 Views
You can use event listeners for clicks.ExampleFollowing is the code − Live Demo Document First Division Second Division document.addEventListener('click', callEventFuncion) function callEventFuncion(event) { var div = document.querySelectorAll('.divDemo'); var titleResult = document.querySelectorAll('.my-title'); var result = Array.apply(0, div).find((v) => v.contains(event.target)); if (result) { console.log(" Incrementing Division Selection"); } else { ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
233 Views
For this, use join(). It will concatenate the string value length-1.ExampleFollowing is the code −var count = 5; var values = new Array(count + 1).join('John'); console.log(values); var count1 = 5; var values1 = new Array(count1).join('John'); console.log(values1);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo274.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo274.js JohnJohnJohnJohnJohn JohnJohnJohnJohn
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
912 Views
With Spread Operator, allow the expression to expand to multiple arguments, elements, variables, etc.You can use JSON.stringify() to convert the JavaScript object to string. Here, we have our object as the result of using spread operator on details1 and details2.ExampleFollowing is the code −var details1 = { name: 'John', age: 21 }; var details2 = { countryName: 'US', subjectName:'JavaScript' }; var result= { ...details1, ...details2}; console.log(JSON.stringify(result));To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo267.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo267.js {"name":"John", "age":21, "countryName":"US", "subjectName":"JavaScript"}Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
155 Views
To validate a specific URL, use regular expression.ExampleThe code is as follows −function validateSoundURL(myURL) { var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/; return myURL.match(regularExpression) && myURL.match(regularExpression)[2] } console.log(validateSoundURL("https://tutorialspoint.com/index")); console.log(validateSoundURL("https://tutorialspoint.com/java"));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo259.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo259.js index java
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
163 Views
Yes, the not not operator is the reverse process of not operator. If any value is true then single ! (not) will return false and !! will return opposite value (true).The not operator −var flag=true; console.log(!flag);The not not operator −var flag=true; console.log(!!flag);ExampleFollowing is the code −var flag=true; console.log("The result of single !=") console.log(!flag); console.log("The result of single !!=") console.log(!!flag)To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo247.jsOutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo247.js The result of single != false The result of single !!= ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
209 Views
The colon (:) can be used when you want to define the property to an object while equal (=) can be used when you want to assign a value to a variable.ExampleFollowing is the code −var studentDetails = { "studentId": 101, "studentName": "John", "studentSubjectName": "Javascript", "studentCountryName": "US" } console.log(studentDetails); var firstName = "David"; console.log(firstName);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo325.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo325.js { studentId: 101, studentName: 'John', studentSubjectName: 'Javascript', studentCountryName: 'US' } David
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
214 Views
To remove child elements, set the innerHTML to ‘’.ExampleFollowing is the code − Document Javascript MySQL Remove the items remove.onclick = () => { const element = document.getElementById("removeAllChildElements"); element.innerHTML = ''; } 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 −Now you can click the button “Remove the items”. It will remove all the elements inside the box.OutputThis will produce the following output −
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
97 Views
Use the map() function correctly to save elements.ExampleFollowing is the code −const addIndexValueToArrayElement = function (arrObject) { const updatedArrayValue = []; arrObject.forEach(function (ob) { const mapValue = ob.map(function (value) { return value + arrObject.indexOf(ob) }) updatedArrayValue.push(mapValue) }) return updatedArrayValue; }; const output = addIndexValueToArrayElement([ [4, 5], [7, 56], [34, 78], ]); console.log(output);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo323.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo323.js [ [ 4, 5 ], [ 8, 57 ], [ 36, 80 ] ]
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
To make it work, you can use onclick with input type = “submit”.ExampleFollowing is the code − Document First Name: Submit var firstName = null; function submitForm(evnt) { evnt.preventDefault(); firstName = document.getElementById("fName").value; document.getElementById("result").innerHTML = "The First Name is=" + firstName; } To run the above program, save the file name anyName.html(index.html). Right click on the file and select ... Read More