Articles on Trending Technologies

Technical articles with clear explanations and examples

Looping over matches with JavaScript regular expressions

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 934 Views

Following is the code for looping over regular expression matches in javaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       color: blueviolet;       font-weight: 500;    }    .sample {       color: red;    } Looping over regex matches There is a cat lying besides the cricket bat and chasing the rat CLICK HERE Click on the above button to match words ...

Read More

How to output JavaScript into a Textbox?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 5K+ Views

You can use the concept of value(). Following is the JavaScript code −Example Live Demo Document FirstNumber SecondNumber: Add Two Nnumbers The addition is:    function add() {       var f = parseInt(document.getElementsByName('input1')[0].value);`       var s =parseInt(document.getElementsByName('input2')[0].value);       var result = f+s;       document.getElementsByName('display')[0].value= result;    } To run the above program, 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.OutputOn clicking the button, the value will be displayed in the textbox. The snapshot is as follows −

Read More

How to override derived properties in JavaScript?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 385 Views

Following is the code to override derived properties in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result,    .sample {       font-size: 18px;       font-weight: 500;       color: rebeccapurple;    }    .result {       color: red;    } Override derived properties Before overriding After overriding CLICK HERE Click on the above button to override the above properties    let sampleEle = document.querySelector(".sample");    let resEle ...

Read More

Get value from div with JavaScript resulting undefined?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 3K+ Views

Use document.getElementById().innerHTML for this. Following is the JavaScript code −Example Document    function display(){       var storedValue = document.getElementById('getValue').innerHTML.value="This is the       value";       console.log("The value is==="+storedValue);    } To run the above program, 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.Following is the output. When you will click the mouse and place the arrow key, you will get the following output.The snapshot is as follows −

Read More

The onchange event is not working in color type input with JavaScript

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 1K+ Views

The onchange event triggers when an element changes. You need to use below syntax.onchange="yourFunctionName(this);"Example Live Demo Document Choose Color    function showValue(c){       console.log(c.value);    } To run the above program, 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.OutputAfter clicking the input type color, you will get the color value in console −

Read More

How to make Format ABC-1234 in JavaScript regular Expressions?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 337 Views

Following is the JavaScript code to make a format like ABC-1234 −Example Live Demo Document ABC1234    function joinTheDashSymbol(m, r1,r2,r3,r4,r5) {       if (r1)          return [r1,r2,r3].join('-');       else          return [r4,r5].join('-');    }    $(".formatting").text(function(i, words) {       words = words.replace(/^(\d{3})(\d{3})(\d{4})|([A-Z]{3})(\d{4})$/,       joinTheDashSymbol);       return words;    }); To run the above program, 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.Output

Read More

Get global variable dynamically by name string in JavaScript?

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 522 Views

Display in alert by using alert(window()). Following is the syntax −alert(window['yourVariableName' + 'yourVariableName' + otherVariableName]);Example Live Demo Document    var globalVariablelocal_print100=100;    print100=1;    alert(window['globalVariable' + 'local_' + print100]); To run the above program, 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.Output

Read More

Object de-structuring in JavaScript.

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 149 Views

Following is the code for object de-structuring in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .sample, .result {       font-size: 18px;       font-weight: 500;       color: red;    }    .result {       color: rebeccapurple;    } Object de-structuring in JavaScript. CLICK HERE Click on the above button to destructure the object above    let sampleEle = document.querySelector(".sample");    let resultEle = document.querySelector(".result");    let obj = { ...

Read More

Explain Optional Catch Binding in JavaScript.

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 487 Views

The optional catch binding introduced in ES2019 allows us to remove the surrounding parentheses of a catch binding i.e. we don’t need to use a variable to store the error object. It is useful especially if we know about the error in advance or even if want to react to an error without knowing about it.Following is the code for the optional catch binding in JavaScript −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result {       font-size: 20px;       ...

Read More

Object.fromEntries() method in JavaScript.

AmitDiwan
AmitDiwan
Updated on 16-Jul-2020 195 Views

The Object.fromEntries() method in JavaScript is used for converting an iterable like an array, map having a key value pair into an object.Following is the code for the Object.fromEntries() method −Example Live Demo Document    body {       font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;    }    .result, .sample {       font-size: 20px;       font-weight: 500;    } Object.fromEntries() method [[firstName, Rohan], [lastName, Sharma], [age, 22]] Object = CLICK HERE Click on the above button to convert the above array into object   ...

Read More
Showing 40631–40640 of 61,248 articles
Advertisements