
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 9150 Articles for Object Oriented Programming

262 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

260 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 −

133 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 ] ]

2K+ Views
The input type submit is not working; it is one of the common issues that every developer faces while working with JavaScript forms. To make it work, you can use an onclick event listener with input type = "submit" or prevent its default behaviour. This article looks at common reasons why a submit button might not work in JavaScript and offers solutions to resolve this issue. Common Reasons for Submit Button Issues The following are listed are some common reasons that may lead to this issue: Missing Event Listener − If you have not ... Read More

149 Views
To repeat string, you can use Array() along with join().ExampleFollowing is the code − Document String.prototype.counter = function (value) { return new Array(value + 1).join(this); } console.log("The repeat string".counter(5)); 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 −

75 Views
If you will use equal operator(=) in if condition the if block will always be executed.You need to use == operator or === .ExampleFollowing is the code −var details = [ { id: 10001, name: "John" }, { id: 10002, name: "Bob" }, { id: 10003, name: "Carol" }, { id: 10004, name: "David" } ] var searchId = 10003; for (var index = 0; index < details.length; index++) { if (details[index].id === searchId) { console.log(details[index].id + " found"); break; } }To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo322.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo322.js 10003 found

2K+ Views
To get the number of true/ false values in an array, the code is as follows −var obj = [ { isMarried: true }, { isMarried: false }, { isMarried: true }, { isMarried: true }, { isMarried: false } ] function numberOfTrueValues(obj) { var counter = 0; for (var index = 0; index < obj.length; index++) { if (obj[index].isMarried === true) { counter++; ... Read More

476 Views
To fetch a specific record, use find() with some condition.ExampleFollowing is the code −var obj=[ { studentId:101, studentName:"John" }, { studentId:102, studentName:"Bob" }, { studentId:103, studentName:"David" } ] const result = obj.find( (o) => { return o.studentId === 102 } ); console.log(result);To run the above program, you need to use the below command −node fileName.js.Here, my file name is demo315.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo315.js { studentId: 102, studentName: 'Bob' }

173 Views
To fix this, you can use map() in JavaScript.The syntax is as follows −var anyVariableName= new Array(yourSize).fill().map(Object);ExampleFollowing is the code −var arrayOfObject = new Array(5).fill().map(Object); console.log(arrayOfObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo311.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo311.js [ {}, {}, {}, {}, {} ]

2K+ Views
Use some conditions to stop after some time.The below code will stop in half a minute.ExampleFollowing is the code − Document var now = new Date().getTime(); var interval = setInterval(function () { if (new Date().getTime() - now > 30000) { clearInterval(interval); return; } console.log("working"); }, 2000); 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 −