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
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
Type inference in Java refers to the automatic detection of the variable’s datatype. This automatic detection usually happens at compile time. It is a feature of Java 10 and it allows the developer to skip declaring the type that is associated with the local variables. Local variables are those which are defined inside a method, initialization block, in for-loops, etc. The type would be usually identified by JDK.Upto Java 9, the following syntax was used to define local variable of a class type −class_name variable_name = new class_name(Arguments);This way, the type of the object would be specified on the right ... Read More
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
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
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
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 −
Radix sort is a sorting technique that sorts the elements based on every digit in every element (or number). Based on the ones place digit (which is also known as least significant digit) and tens place digit (which is also known as most significant digit), hundreds place digit, and so on, the elements are sorted.ExampleFollowing is an example for Radix Sort in Java − Live Demoimport java.util.*; public class my_radix_sorting { static int get_max_val(int my_arr[], int arr_len) { int max_val = my_arr[0]; for (int i = 1; i < arr_len; i++) ... Read More
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
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