- 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 9311 Articles for Object Oriented Programming
16K+ Views
To filter JSON data with multiple objects, you can use the concept of filter along with ==.Exampleconst jsonObject= [ { studentId:101, studentName:"David" }, { studentId:102, studentName:"Mike" }, { studentId:103, studentName:"David" }, { studentId:104, studentName:"Bob" } ] var result=jsonObject.filter(obj=> obj.studentName == "David"); console.log(result);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo194.js. This will produce the following output −PS C:\Users\Amit\javascript-code> node demo194.js [ { studentId: 101, studentName: 'David' }, { studentId: 103, studentName: 'David' } ]
1K+ Views
For this, you can use timeZone from JavaScript i.e. specific time zones for Asia and America respectively.For Asian Time Zonevar todayDateTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"});For American Time Zonevar americaDateTime = new Date().toLocaleString("en-US", {timeZone: "America/New_York"});Examplevar todayDateTime = new Date().toLocaleString("en-US", {timeZone: "Asia/Kolkata"}); todayDateTime = new Date(todayDateTime); console.log("The Asia Date time is="); console.log(todayDateTime) var americaDateTime = new Date().toLocaleString("en-US", {timeZone: "America/New_York"}); americaDateTime = new Date(americaDateTime); console.log("The America Date time is="); console.log(americaDateTime);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo193.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo193.js The Asia Date time is= ... Read More
2K+ Views
Let’s say the following is our dropdown (select) − Javascript MySQL MongoDB Java Following is the code to display the selected value on Console −Example Live Demo Document Javascript MySQL MongoDB Java function selectedSubjectName() { var subjectIdNode = document.getElementById('subjectName'); var value = subjectIdNode.options[subjectIdNode.selectedIndex].text; console.log("The selected value=" + value); } To run the above program, save the file name “anyName.html(index.html)” and right click on the file. Select the option ... Read More
891 Views
In order to call the parent method when both parent and child have the same method name and signature.You can use the below syntax −console.log(yourParentClassName.prototype.yourMethodName.call(yourChildObjectName));Exampleclass Super { constructor(value) { this.value = value; } display() { return `The Parent class value is= ${this.value}`; } } class Child extends Super { constructor(value1, value2) { super(value1); this.value2 = value2; } display() { return `${super.display()}, The Child Class value2 is=${this.value2}`; } } var childObject = new Child(10, 20); ... Read More
115 Views
Let’s say the following is our Student object −var studentObject = new Object(); studentObject["studentFirstName"] = "John"; studentObject["studentLastName"] = "Doe"; studentObject["studentAge"] = 22; studentObject["studentCountryName"] = "US"; studentObject["studentCollegeName"] = "MIT"; studentObject["studentSubjectName"] = "JavaScript";Let’s find the length.You can use the concept of keys available in object and if the key is present then increment the counter variable and return the counter after completing the for loop.Examplevar studentObject = new Object(); studentObject["studentFirstName"] = "John"; studentObject["studentLastName"] = "Doe"; studentObject["studentAge"] = 22; studentObject["studentCountryName"] = "US"; studentObject["studentCollegeName"] = "MIT"; studentObject["studentSubjectName"] = "JavaScript"; Object.findLength = function (stObject) { var counter = 0, k; for (k in ... Read More
2K+ Views
Let’s say the following are our two arrays −var firstArray = ['John', 'David', 'Bob']; var secondArray = ['Mike', 'Sam', 'Carol'];To combine two arrays into an array of objects, use map() from JavaScript.Examplevar firstArray = ['John', 'David', 'Bob']; var secondArray = ['Mike', 'Sam', 'Carol']; var arrayOfObject = firstArray.map(function (value, index){ return [value, secondArray[index]] }); console.log("The First Array="); console.log(firstArray); console.log("The Second Array="); console.log(secondArray); console.log("The mix Of array object="); console.log(arrayOfObject);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo190.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo190.js The First Array= [ 'John', ... Read More
2K+ Views
For this, you can use onclick=”yourFunctionName()”, and −document.getElementById(“”).value=’’Example Live Demo Document ClearInputText function clearTheTextField(){ console.log("The text box value="+document.getElementById('txtBox').value) document.getElementById('txtBox').value = ''; } To run the above program, just save the file name anyName.html(index.html) and right click on the file and select the option open with live server in VS Code editor.OutputThis will produce the following output −Now enter some value into the text box and click the button ClearInputText.After entering the value, clicking the button.This will produce the following output −
239 Views
As we know the stack works on the principle of Last in first out. At first, to insert into another stack you need to pop() all elements from the first stack and push into the second stack.Examplevar myFirstStack=[10, 20, 30, 40, 50, 60, 70]; var mySecondStack=[]; for(;myFirstStack.length;){ mySecondStack.push(myFirstStack.pop()); } console.log("After popping the all elements from the first stack="); console.log(myFirstStack); console.log("After pushing (inserting) all the elements into the second stack="); console.log(mySecondStack);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo189.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo189.js After popping ... Read More
454 Views
For this, use regular expression with digit along with $.Examplevar groupValues1 = "10 10 10"; var groupValues2 = "10 10 10 10"; var groupValues3 = "10 10"; var regularExpression = /^(\d+)(\s)\1\2\1$/; var isValidGroup1 = regularExpression.test(groupValues1); var isValidGroup2 = regularExpression.test(groupValues2); var isValidGroup3 = regularExpression.test(groupValues3); if(isValidGroup1==true) console.log("This is a valid group="+groupValues1); else console.log("This is not a valid group="+groupValues1); if(isValidGroup2==true) console.log("This is a valid group="+groupValues2); else console.log("This is not a valid group="+groupValues2); if(isValidGroup3==true) console.log("This is a valid group="+groupValues3); else console.log("This is not a valid group="+groupValues3);To run the above program, you need to use the following command −node ... Read More
558 Views
For this, use the concept of scrollTop and scrollHeight.Example Live Demo Document #scrollDemo { height: 300px; overflow-y: scroll; } #scrollDataFeatures { height: 500px; background-color: skyblue; } See the below Message and Scroll UP var scrollData = document.getElementById("scrollDemo"); scrollData.scrollTop = scrollData.scrollHeight setInterval(() =>{ var heading3Data = document.createElement("h3"); heading3Data.innerHTML = "Scroll Down...Please Scroll UP" scrollData.appendChild(heading3Data); scrollData.scrollTop ... Read More