
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

516 Views
To toggle hide class only on selected div, you need to set event on click button. Let’s say you need to hide a specific div on the click of + sign.To get font + or - icon, you need to link font-awesome −Following is the code to toggle hide class on clicking + sign −Example Live Demo Document .hideDiv { display: none; } Customer 1 John US Customer 2 David AUS $(".fa-plus").on("click", function(){ $(this).parent().siblings('.secondDetails').toggleClass("hideDiv"); }); To run ... Read More

162 Views
Let’s say the following are our arrays −var firstNamesArray=["John", "David", "Bob", "Sam", "Carol"]; var secondNamesArray=["Mike", "Carol", "Adam", "David"];The easiest way to perform array intersection is by using filter() along with includes(). Following is the code −Examplevar firstNamesArray=["John", "David", "Bob", "Sam", "Carol"]; var secondNamesArray=["Mike", "Carol", "Adam", "David"]; var intersectionOfArray=[]; intersectionOfArray=firstNamesArray.filter(v => secondNamesArray.includes(v)); console.log("Intersection of two array="); console.log(intersectionOfArray);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo141.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo141.js Intersection of two array= [ 'David', 'Carol' ]Read More

918 Views
For this, use hasOwnProperty(). Following is the code −Examplevar markDetails1 ={ 'marks1': 78, 'marks2': 65 }; var markDetails2 ={ 'marks2': 89, 'marks3': 90 } function updateJavaScriptObject(details1, details2) { const outputObject = {}; Object.keys(details1) .forEach(obj => outputObject[obj] = (details2.hasOwnProperty(obj) ? details2[obj] : details1[obj])); return outputObject; } console.log(updateJavaScriptObject(markDetails1, markDetails2));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo140.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo140.js { marks1: 78, marks2: 89 }

194 Views
For this, you can use match() along with regular expression. Following is the code −Examplevar originalString="JJJJOHHHHNNNSSSMMMIIITTTTHHH"; var regularExpression=/(.)\1*/g; console.log("The original string="+originalString); var splitting=originalString.match(regularExpression); console.log("After splitting the original string="); console.log(splitting);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo139.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo139.js The original string=JJJJOHHHHNNNSSSMMMIIITTTTHHH After splitting the original string=[ 'JJJJ', 'O', 'HHHH', 'NNN', 'SSS', 'MMM', 'III', 'TTTT', 'HHH' ]

542 Views
Let’s say following is our array −var numbers=[10,50,80,60,89];To find the second largest element, the code is as follows −Examplevar numbers=[10,50,80,60,89]; var firstLargerNumber = Number.MIN_SAFE_INTEGER; var secondlargerNumber = firstLargerNumber; for(var tempNumber of numbers){ if(tempNumber > firstLargerNumber){ secondlargerNumber = firstLargerNumber; firstLargerNumber = tempNumber; } else if(tempNumber > secondlargerNumber){ secondlargerNumber = tempNumber; } } console.log("The second largest number="+secondlargerNumber);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo138.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo138.js The second largest number=80

11K+ Views
Let’s say the following is our button −SubmitOn the basis of button id, on form submission, generate an alert −$("#submitForm").click(function() { alert("The Form has been Submitted."); });Example Live Demo Document CollegeId= CollegeName= Submit $("#submitForm").click(function() { alert("The Form has been Submitted."); }); 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 −After clicking the button, you can see the following output −

383 Views
To get the yesterday date, first of all get the current date and subtract 1 from the current and use the function setDate(). The syntax is as follows −yourCurrentDateVariableName.setDate(yourCurrentDateVariableName.getDate() - 1);At first, get the current date −var currentDate = new Date();Now, get yesterday’s date with the following code −Examplevar currentDate = new Date(); console.log("The current date="+currentDate); var yesterdayDate = currentDate.setDate(currentDate.getDate()- 1); console.log("The yesterday date ="+new Date(yesterdayDate));To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo137.js. This will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo137.js The current date=Fri Jul 31 2020 ... Read More

420 Views
At first, set the characters and numbers −var storedCharacters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';To generate randomly, use Math.random(). Following is the code −Examplefunction generateRandom3Characters(size) { var generatedOutput= ''; var storedCharacters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; var totalCharacterSize = storedCharacters.length; for ( var index = 0; index < size; index++ ) { generatedOutput+=storedCharacters.charAt(Math.floor(Math.random() * totalCharacterSize)); } return generatedOutput; } console.log(generateRandom3Characters(3));To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo136.js. This will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo136.js lq4

202 Views
Following is our object −const customerDetails=[ {customerFirstName: "David"}, {customerLastName: "Miller"}, {customerCountryName: "US"}, {customerAge: "29"}, {isMarried: false}, {customerCollegeName: null} ];Let’s assign values to a computed property using slice() along with map().Exampleconst customerDetails=[ {customerFirstName: "David"}, {customerLastName: "Miller"}, {customerCountryName: "US"}, {customerAge: "29"}, {isMarried: false}, {customerCollegeName: null} ]; const newCustomerDetails = customerDetails.slice(2, 4).concat(customerDetails[5]).map(obj=>({ propertyKey: Object.keys(obj)[0], propertyValue: Object.values(obj)[0] })); console.log(newCustomerDetails);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo135.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo135.js [ { propertyKey: ... Read More

430 Views
Let’s say the following is our table − John David Mike Use the following with text() to get last item −$('table tr:last td')Example Live Demo Document John David Mike var lastValue= $('table tr:last td').text(); console.log("The last value is="+lastValue); 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 −