Concatenate String Value Length -1 in JavaScript

AmitDiwan
Updated on 09-Nov-2020 07:54:56

316 Views

For this, use join(). It will concatenate the string value length-1.ExampleFollowing is the code −var count = 5; var values = new Array(count + 1).join('John'); console.log(values); var count1 = 5; var values1 = new Array(count1).join('John'); console.log(values1);To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo274.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo274.js JohnJohnJohnJohnJohn JohnJohnJohnJohn

Using JSON.stringify to Display Spread Operator Result

AmitDiwan
Updated on 09-Nov-2020 07:46:10

1K+ Views

With Spread Operator, allow the expression to expand to multiple arguments, elements, variables, etc.You can use JSON.stringify() to convert the JavaScript object to string. Here, we have our object as the result of using spread operator on details1 and details2.ExampleFollowing is the code −var details1 = { name: 'John', age: 21 }; var details2 = { countryName: 'US', subjectName:'JavaScript' }; var result= { ...details1, ...details2}; console.log(JSON.stringify(result));To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo267.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo267.js {"name":"John", "age":21, "countryName":"US", "subjectName":"JavaScript"}Read More

Validate Tutorialspoint URL via JavaScript Regex

AmitDiwan
Updated on 09-Nov-2020 07:31:44

210 Views

To validate a specific URL, use regular expression.ExampleThe code is as follows −function validateSoundURL(myURL) {    var regularExpression = /^https?:\/\/(tutorialspoint\.com)\/(.*)$/;    return myURL.match(regularExpression) && myURL.match(regularExpression)[2] } console.log(validateSoundURL("https://tutorialspoint.com/index")); console.log(validateSoundURL("https://tutorialspoint.com/java"));To run the above program, you need to use the following command −node fileName.js.Here, my file name is demo259.js.OutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo259.js index java

Set a Fixed Element and Scroll Another in jQuery

AmitDiwan
Updated on 09-Nov-2020 07:30:18

2K+ Views

Let’s say the following is our fixed element div −    Fixed The CSS style to fix the above element −.fixedElement {    position: fixed;    background-color: skyblue;    top: 0;    left: 0;    right: 0; }Following is our element, which will be scrolled −    David Miller Now, use the window.scrollTo().ExampleLet us see the complete code − Live Demo            Document    .fixedElement {       position: fixed;       background-color: skyblue;       top: 0;       left: 0;       right: ... Read More

Access File Contents in jQuery Callback Function

AmitDiwan
Updated on 09-Nov-2020 07:24:35

681 Views

Let’s say the following is our file and we need to read this file using jQuery.The name of the file details −ExampleFollowing is the code − Live Demo            Document        function chooseFile() {       dataFromMyFile = document.getElementById("readFileDemo").files[0];       readDataFromFile = new FileReader();       readDataFromFile.onload = () => {          data = readDataFromFile.result;          console.log("Your File Data is=");          console.log(data);       };       readDataFromFile.readAsText(dataFromMyFile);    } ... Read More

Output Only the First Word from Select List Value in jQuery

AmitDiwan
Updated on 09-Nov-2020 06:58:31

996 Views

Let’s say the following is our select −    Get First Name    Get First Name Only To get only the first word, use split() on the basis of space and can select the 0th index value.ExampleFollowing is the code − Live Demo            Document        Get First Name    Get First Name Only        function showFirstValue(choosenObject) {       var allValues = choosenObject.value.split(" ");       var firstValue = allValues[0];       console.log("The first Name=" + firstValue);    } ... Read More

Put URL into a Variable When Button is Clicked in jQuery

AmitDiwan
Updated on 09-Nov-2020 06:55:08

822 Views

For this, call a function on button click.ExampleFollowing is the code − Live Demo            Document           ClickMeToCopyURL        https://www.tutorialspoint.com/index/    function demoForCopyURL(e) {       event.preventDefault();       var rootText = event.target.parentElement.innerText       var btnText = event.target.innerText       var originalURLValue = rootText.substring(btnText.length + 1)       console.log("THE URL IS=" + originalURLValue)    } 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 VSCode editor −OutputThis will produce the following output on console −On clicking the button, you will get the following output on console −

Difference Between Single Quote and Double Quote in PowerShell

Chirag Nagrekar
Updated on 09-Nov-2020 06:49:46

5K+ Views

There is no such difference between the single quote (‘) and double quote(“) in PowerShell. It is similar to a programming language like Python. We generally use both quotes to print the statements.ExamplePS C:\> Write-Output 'This will be printed using Single quote' This will be printed using Single quote PS C:\> Write-Output "This will be printed using double quote" This will be printed using double quoteBut when we evaluate any expression or print variable it makes a clear difference.$date = Get-Date Write-Output 'Today date is : $date' Today date is : $date Write-Output "Today date is : $date" Today date ... Read More

Remove Next Element Using jQuery

AmitDiwan
Updated on 09-Nov-2020 06:37:54

2K+ Views

To remove the next element in jQuery, use the remove().ExampleFollowing is the code − Live Demo            Document                    cancel(X)          Demo                            cancel(X)          Demo                            cancel(X)          Demo                          $(".demo1").click(function () {       $(this).parent().next("hr").remove();       $(this).parent().remove();       return false;    }); 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 VSCode editor −OutputThis will produce the following output −Whenever you click the cancel(X), the jQuery will remove the element. This will produce the following output −

Not-Not Operator in JavaScript: Equivalent to Reverse Process of Not Operator

AmitDiwan
Updated on 09-Nov-2020 06:25:30

247 Views

Yes, the not not operator is the reverse process of not operator. If any value is true then single ! (not) will return false and !! will return opposite value (true).The not operator −var flag=true; console.log(!flag);The not not operator −var flag=true; console.log(!!flag);ExampleFollowing is the code −var flag=true; console.log("The result of single !=") console.log(!flag); console.log("The result of single !!=") console.log(!!flag)To run the above program, you need to use the following command −node fileName.js. Here, my file name is demo247.jsOutputThis will produce the following output on console −PS C:\Users\Amit\javascript-code> node demo247.js The result of single != false The result of single !!= ... Read More

Advertisements