
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 6710 Articles for Javascript

54 Views
To check this, use the concept of getter, i.e. the get property. Following is the code −Exampleclass Student{ constructor(studentMarks1, studentMarks2){ this.studentMarks1 = studentMarks1 this.studentMarks2 = studentMarks2 var alteredValue = this; this.getValues = { get studentMarks1() { return alteredValue.studentMarks1 }, get studentMarks2() { return alteredValue.studentMarks2 } } } } var johnSmith = new Student(78, 79) console.log("Before ... Read More

302 Views
Let’s say following is our string −my name is JOHN SMITHUse sort() along with regular expression /[A-Z]/ to move all capital letters to the beginning of the string/Examplevar moveAllCapitalLettersAtTheBeginning = [...' my name is JOHN SMITH '] .sort((value1, value2) => /[A-Z]/.test(value1) ? /[A-Z]/.test(value2) ? 0 : -1 : 0).join(' '); console.log("After moving the all capital letters at the beginning="); console.log(moveAllCapitalLettersAtTheBeginning);To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo199.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo199.js After moving the all capital letters at the beginning= J O H N ... Read More

171 Views
Use the return keyword for outsider function call. Following is the code −Examplevar substractMethod = function () { var firstValue =1000, thirdValue= 200; var divideMethod = function (){ var secondValue =500; console.log("The result of divideMethod()="+(firstValue/secondValue)); return (firstValue-secondValue); } return divideMethod; } var result = subtractMethod(); console.log("The result of substractMethod()="+result());To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo198.js.OutputThis will produce the following output −PS C:\Users\Amit\javascript-code> node demo198.js The result of divideMethod()=2 The result of subtractMethod()=500

727 Views
For this, use the concept of toString(‘utf8’). Following is the code −In the code below, there are detailed explanations about the buffer.Examplevar actualBufferObject = Buffer.from('[John Smith]', 'utf8') console.log("The actual buffer object="); console.log(JSON.stringify(actualBufferObject)) console.log("Get back the original object="); console.log(actualBufferObject.toString('utf8')); var myObjectValue = '[John Smith]'; console.log("The data you are getting from the buffer is equal to ASCII code equivalent...") for (var counter = 0; counter < myObjectValue.length; counter++) { console.log("The ascii value of " + myObjectValue[counter] + " is =" + (myObjectValue.charCodeAt(counter))); }To run the above program, you need to use the following command −node fileName.js.Here, my file name is ... Read More

606 Views
In order to get rid of null values inserted into a table, you need to check the condition while entering the value.The condition to check NULL must be as follows −while( !( yourVariableName1==null || yourVariableName2==null || yourVariableName3==null…...N){ // yourStatement1 . . N }The above logic will never allow inserting the null values.Now you can use for loop and insert value into the table without NULL. Following is the code −Example Live Demo Document Demo Of Inserting the value into the table This is demo on the javascript ... Read More

252 Views
Let’s say the following is our array &mius;var subjectNameAlongWithMarks = [ ["JavaScript", 78], ["Java", 56], ["JavaScript", 58], ["MySQL", 77], ["MongoDB", 75], ["Java", 98] ]Above, we have repeated values, which we need to remove by comparing the duplicate values 0th index. Use the concept of Set() from JavaScript for this −Examplevar subjectNameAlongWithMarks = [ ["JavaScript", 78], ["Java", 56], ["JavaScript", 58], ["MySQL", 77], ["MongoDB", 75], ["Java", 98] ] var distinctResult = subjectNameAlongWithMarks.filter(function ([value]){ return !this.has(value) && !!this.add(value) }, new Set()) console.log(distinctResult);To run the above program, you need to use ... Read More

461 Views
For this, use jQuery() with id property. Following is the code −Example Live Demo Document .changeColor { color: red }; Javascript MySQL MongoDB Python jQuery("#selectDemo").click(function () { jQuery(this).toggleClass("changeColor"); if (jQuery(this).hasClass("changeColor")) { jQuery(".isSelected").prop("checked", true); jQuery(this).val("Want To UnSelect All Values"); } else { ... Read More

1K+ Views
Yes, parent and child classes can have a method with the same name.Exampleclass Parent { constructor(parentValue) { this.parentValue = parentValue; } //Parent class method name which is same as Child Class method name. showValues() { console.log("The parent method is called....."); console.log("the value is="+this.parentValue); } } class Child extends Parent { constructor(parentValue, childValue){ super(parentValue); this.childValue = childValue; } //Child class method name which is same as Parent Class method name. showValues() { console.log("The child ... Read More

17K+ 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' } ]

2K+ 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