PowerShell alias is a good way to use the shortcut name for the Parameter instead of writing the full name of the parameter. For example, you can refer to Server as ServerName, AppID as the ApplicationID.So you don’t have to use the whole name of the parameter and it is easy to remember as well.Examplefunction Aliastest{ param( [parameter(Mandatory=$true)] [Alias("Server")] [string]$ServerName ) Write-Output "Server name is $ServerName" }Now we can use the Server instead of ServerName while passing the arguments.PS C:\> Aliastest -server "Test1-Win2k16" Server name is Test1-Win2k16
To find the network adapter driver version using PowerShell, we can use the Get-NetAdapter cmdlet. First, let look at how the network adapter driver version looks like from GUI.Get-NetAdapter will retrieve all the Physical and Virtual network adapters unless specified.This cmdlet has a property called DriverVersion, DriverDate, and DriverProvider. You can select it.ExampleGet-NetAdapter | Select Name, InterfaceDescription, DriverVersion, DriverDate, DriverProviderOutputName : Wi-Fi InterfaceDescription : Intel(R) Wi-Fi 6 AX201 160MHz DriverVersion : 21.80.2.1 DriverDate : 2020-02-25 DriverProvider ... Read More
Yes, you can pass default parameters in nested objects.Following is the code −ExampleFollowing is the code −function callBackFunctionDemo({ cl: { callFunctionName = "callBackFunction", values = 100 } = {} } = {}) { console.log(callFunctionName); console.log(values); } //This will print the default value. // 100 callBackFunctionDemo(); //This will print the given value. //500 callBackFunctionDemo({ cl: { values: 500 } });To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo296.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo296.js callBackFunction 100 callBackFunction 500
Let’s say our original string is the following with repeated letters −var values = "DDAAVIDMMMILLERRRRR";We want to remove the repeated letters and precede letters with numbers. For this, use replace() along with regular expression.ExampleFollowing is the code −var values = "DDAAVIDMMMILLERRRRR"; var precedingNumbersInString = values.replace(/(.)\1+/g, obj => obj.length + obj[0]); console.log("The original string value=" + values); console.log("String value after preceding the numbers ="); console.log(precedingNumbersInString);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo295.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo295.js The original string value=DDAAVIDMMMILLERRRRR String value ... Read More
For this, use Object.keys() and set one key on each iteration as null using a for loop..ExampleFollowing is the code −var objectValues = { "name1": "John", "name2": "David", "address1": "US", "address2": "UK" } for (var tempKey of Object.keys(objectValues)) { var inEachIterationSetOneFieldValueWithNull = { ...objectValues, [tempKey]: null }; console.log(inEachIterationSetOneFieldValueWithNull); }To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo294.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo294.js { name1: null, name2: 'David', address1: 'US', address2: 'UK' ... Read More
Use localStorage.setItem(“anyKeyName”, yourValue) to set the value in local storage and if you want to fetch value then you can use localStorage.getItem(“yourKeyName”)ExampleFollowing is the code − Live Demo Document var textBoxNameHTML = document.getElementById('txtName'); textBoxNameHTML.addEventListener('change', (e) => { localStorage.setItem("textBoxValue", e.target.value); }); To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output on console −Now, I ... Read More
Let’s say we have the following array −var studentDetails = [ [89, "John"], [78, "John"], [94, "John"], [47, "John"], [33, "John"] ];And we need to sort the array on the basis of the first item i.e. 89, 78, 94, etc. For this, use sort().ExampleFollowing is the code −var studentDetails = [ [89, "John"], [78, "John"], [94, "John"], [47, "John"], [33, "John"] ]; studentDetails.sort((first, second) => second[0] - first[0]) console.log(studentDetails);To run the above program, you need to use the ... Read More
Let’s say the following is our array −var details = [ { studentName: "John", studentMarks: [78, 98] }, { studentName: "David", studentMarks: [87, 87] }, { studentName: "Bob", studentMarks: [48, 58] }, { studentName: "Sam", studentMarks: [98, 98] }, ]We need to remove the duplicate property value i.e. 87 is repeating above. We need to remove it.For this, use the concept of map().ExampleFollowing is the code −var details ... Read More
For this, use the addEventListener() with mousedown event.ExampleFollowing is the code − Document document.addEventListener("mousedown", function () { console.log("Mouse down event is happening"); }); To run the above program, save the file name “anyName.html(index.html)”. Right click on the file and select the option “Open with Live Server” in VS Code editor.OutputThis will produce the following output on console −When you click the mouse, the event will generate. The console output is shown below −
At first, set a new Date in JavaScript −var dateValue = new Date("2021-01-12 10:10:20");Use new Date() along with setHours() and getHours() to add time.ExampleFollowing is the code −var dateValue = new Date("2021-01-12 10:10:20"); dateValue.setHours(dateValue.getHours() + 2); console.log("The date value is=" + dateValue.toString()); console.log("Only Hours value after incrementing=" + dateValue.getHours());To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo291.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo291.js The date value is=Tue Jan 12 2021 12:10:20 GMT+0530 (India Standard Time) Only Hours value after incrementing=12Read More