- 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
804 Views
You need to use currentDate with the help of new Date().getDate(). The syntax is as follows −var anyVariableName= yourCurrentDate - yourSubstractDateOfCurrentMonth;Examplevar currentDate=new Date().getDate(); var substractDate=new Date("2020-07-01").getDate(); const numberOfDaysInCurrentMonthOnly = currentDate-substractDate; console.log(numberOfDaysInCurrentMonthOnly);NoteToday’s date is - 28-07-2020To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo129.jsPS C:\Users\Amit\JavaScript-code> node demo129.js 27
1K+ Views
For this, use the document.getElementByClassName(). Following is the code −Example Live Demo Document Click The Button to get an alert for (var clickButton of document.getElementsByClassName("clickTheButton")) clickButton.addEventListener("click", alertMeessage); function alertMeessage() { alert("You have clicked the button"); } 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 −When you click the button, an alert message will be visible. This will produce the following output −
153 Views
Let’s say, we have subject records with the time when we are planning to study them −const scheduleDetails = [ { subjectName: 'JavaScript', studyTime: '5 PM - 11 PM' }, { subjectName: 'MySQL', studyTime: '12 AM - 4PM' } ]Here is how we can use the map(). Following is the code −Exampleconst scheduleDetails = [ { subjectName: 'JavaScript', studyTime: '5 PM - 11 PM' }, { subjectName: 'MySQL', studyTime: '12 AM - 4PM' } ] function timeToReadSubjectName(scheduleDetails) { var currentTime = new Date().getHours(); let result = ''; scheduleDetails.map(obj => { ... Read More
972 Views
To format HSON string in JavaScript, use JSON.stringify() with some parameters. Following is the code −Examplevar details = { studentId: 101, studentFirstName: 'David', studentLastName: 'Miller', studentAge:21, subjectDetails: { subjectId: 'JavaScript_101', subjectName: 'Introduction to JavaScript', } }; console.log("Not Pretty JSON Format=") console.log(JSON.stringify(details)); console.log("Pretty JSON Format=") console.log(JSON.stringify(details, null, 3));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo127.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo127.js Not Pretty JSON Format= {"studentId":101, "studentFirstName":"David", "studentLastName":"Miller", "studentAge":21, "subj ectDetails":{"subjectId":"JavaScript_101", "subjectName":"Introduction to JavaScript"}} Pretty ... Read More
2K+ Views
To check for consecutive numbers like 100, 101, 102, etc., use the concept of reduce(). TRUE would be returned for consecutive numbers, else false is the return value.Exampleconst sequceIsConsecutive = (obj) => Boolean(obj.reduce((output, lastest) => (output ? (Number(output.number) + 1=== Number(lastest.number) ? lastest : false) : false))); console.log("Is Consecutive="+sequceIsConsecutive ([{ number: '100' }, {number: '101'} ,{number: '102' }])); console.log("Is Consecutive="+sequceIsConsecutive([{ number: '100' }, {number: '102'} ,{number: '104' }]));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo126.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo126.js Is Consecutive=true Is Consecutive=falseRead More
125 Views
Following is our object −var customerDetails ={ "customerFirstName":"David", "customerLastName":"Miller", "customerAge":21, "customerCountryName":"US" };Now, create a new array and use push() function. Following is the code −Examplevar customerDetails ={ "customerFirstName":"David", "customerLastName":"Miller", "customerAge":21, "customerCountryName":"US" }; var customerObjectToArray = []; customerObjectToArray.push(customerDetails); console.log(customerObjectToArray);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo125.js.OutputThis will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo125.js [ { customerFirstName: 'David', customerLastName: 'Miller', customerAge: 21, customerCountryName: 'US' } ]
4K+ Views
Let’s say the following is our input type with value, “John Smith” −To change, use the attr() method −$('#changeTheName').attr('value', 'Please enter your name.......');You need to use the concept of attr(). Following is the code −Example Live Demo Document $('#changeTheName').attr('value', 'Please enter your name.......'); 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 −
351 Views
Let’s say the following is our file name −var actualJavaScriptFileName = "demo.js";Following is the word to be inserted before the dot extension −var addValueBetweenFileNameAndExtensions = "programming";At first, you need to split() the file name on the basis of dot(.) and then to insert a character, you can use the concept of template variables. Following is the code −Examplevar addValueBetweenFileNameAndExtensions = "programming"; var actualJavaScriptFileName = "demo.js"; console.log("The actual File name="+actualJavaScriptFileName); var [fileName, fileExtension] = actualJavaScriptFileName.split('.'); console.log("After adding into the file name="); console.log(`${fileName}- ${addValueBetweenFileNameAndExtensions}.${fileExtension}`)To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo124.js. ... Read More
312 Views
To convert string type value to array type, use the parse() method. Following is the code −Examplevar customerDetails='[ {"name": "John", "countryName": "US"}, {"name": "David", "countryName": "AUS"}, {"name": "Bob", "countryName": "UK"} ]'; console.log("The actual value="+customerDetails); var convertStringToArray=JSON.parse(customerDetails); console.log("After converting string to array objects="); console.log(convertStringToArray);To run the above program, you need to use the following command −node fileName.js.OutputHere, my file name is demo123.js. This will produce the following output −PS C:\Users\Amit\JavaScript-code> node demo123.js The actual value=[{"name": "John", "countryName": "US"}, {"name": "David", "countryName": "AUS"}, {"name": "Bob", "countryName": "UK"}] After converting string to array objects=[ { name: 'John', countryName: 'US' ... Read More
789 Views
At first, set the element −Replace This strong tagThe id attribute set above would be used set the text using # −$(document).ready(function(){ $("#strongDemo").html("Actual value of 5+10 is 15....."); });Example Live Demo Document Replace This strong tag $(document).ready(function(){ $("#strongDemo").html("Actual value of 5+10 is 15....."); }); 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 −