
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
AmitDiwan has Published 10744 Articles

AmitDiwan
2K+ Views
Take an array to store the frequency of each character. If similar character is found, then increment by one otherwise put 1 into that array.Let’s say the following is our string −var sentence = "My name is John Smith";Following is the JavaScript code to count occurrences −Examplevar sentence = "My ... Read More

AmitDiwan
694 Views
Let’s say we have the following string with special character sequence −var fullName=" John Smith ";To separate the above string into substring, use regex and then split(). The syntax is as follows −var anyVariableName=(/\s*\s*/g); var anyVariableName=yourVariableName.trim().split(yourVariableName);Following is the complete JavaScript code −Examplevar fullName=" John Smith "; console.log("The Value="+fullName); ... Read More

AmitDiwan
598 Views
To round the decimal number to the nearest tenth, use toFixed(1) in JavaScript. The syntax is as follows −var anyVaribleName=yourVariableName.toFixed(1)Let’s say the following is our decimal number −var decimalValue =200.432144444555; console.log("Actual value="+decimalValue)Let’s now round the decimal number. Following is the code −Examplevar decimalValue =200.432144444555; console.log("Actual value="+decimalValue) var modifiedValue=decimalValue.toFixed(1) console.log("Modified value="+ ... Read More

AmitDiwan
850 Views
To get value from the first checkbox, which is not hidden, use the :visible selector. Following is the code −Example Live Demo >Document .notShown { display: none; } ... Read More

AmitDiwan
2K+ Views
To store and retrieve arrays into and from data attributes, use the data() method in jQuery. Following is the syntax −var anyVariableName= $('#yourIdName).data('yourJavscriptArrayName');Following is the jQuery code −Example Live Demo Document var value = $('#test').data('details'); alert(value); ... Read More

AmitDiwan
301 Views
The easiest way to detect keypresses in JavaScript, use the onKeyPress event handler −document.onkeypressThe key press is matched with the keyCode property, which returns the Unicode character code of the key that triggered the onkeypress event.Example Live Demo Document document.onkeypress ... Read More

AmitDiwan
673 Views
To find out which characters key is pressed, use the window.event along with keyCode. Following is the code −Example Live Demo Document function keyPressName(myEventKeyName){ var pressedKey; if(window.event){ ... Read More

AmitDiwan
2K+ Views
To avoid unexpected string concatenation while concatenating strings, multiple strings, and numbers, use backticks.We have the following −const concatValue = 'John, David, Mike'; var friendNames= `${concatValue}`;The above value is concatenated with a string and number −var studentNameWithFriends=` ${concatValue}| 'Carol' | 24 ` ;Following is the complete JavaScript code for concatenation ... Read More

AmitDiwan
525 Views
To display only the visible text, use the concept of − visible selector in jQuery. It selects the element currently visible. Following is the code −Example Live Demo Document Test Class Demo class $('#myDiv').children(":visible").text() To ... Read More

AmitDiwan
575 Views
To parse JSON, use parseJSON() and for displaying a specific pair, use the $.each() function.Let’s say the following is our JSON, which is parsed −const APIData = '[{"Name":"John", "Age":21}, {"Name":"David", "Age":24}, {"Name":"Bob", "Age" :20}]'; const getObject = jQuery.parseJSON(APIData);Now, let’s see the complete code and fetch the “Name” pairs −Example Live Demo ... Read More