Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Object Oriented Programming Articles
Page 153 of 589
Parse JSON in JavaScript to display a specific name/value pair?
To parse JSON in JavaScript, you can use the native JSON.parse() method or jQuery's parseJSON() function. To display specific name/value pairs, you can use array methods like forEach() or jQuery's $.each() function. Using Native JSON.parse() The modern approach uses the built-in JSON.parse() method: Parse JSON Example const APIData = '[{"Name":"John", "Age":21}, {"Name":"David", "Age":24}, {"Name":"Bob", ...
Read MoreDiagonal product of a matrix - JavaScript
Suppose, we have a 2-D array representing a square matrix like this − const arr = [ [1, 3, 4, 2], [4, 5, 3, 5], [5, 2, 6, 4], [8, 2, 9, 3] ]; We are required to write a function that takes in this array and returns the product of the elements present at the principal diagonal of the matrix. Principal Diagonal Elements The principal diagonal consists of elements where the row index equals the column index (i === j). For ...
Read MoreHow do I display only the visible text with jQuery?
To display only the visible text in jQuery, use the :visible selector. This selector targets elements that are currently visible on the page (not hidden with display:none, visibility:hidden, or other hiding methods). Syntax $(selector).filter(':visible') $(selector + ':visible') $(':visible') Example Visible Text with jQuery Hidden Text Visible Text ...
Read MoreHow to find out what character key is pressed in JavaScript?
To find out which character key is pressed in JavaScript, you can use various methods. The modern approach uses the key property, while legacy methods relied on keyCode. Modern Approach: Using event.key The key property directly returns the character that was pressed, making it the preferred method: Key Detection - Modern Method Type in the input field below: ...
Read MoreCorner digit number difference - JavaScript
We are required to write a JavaScript function that takes in a number, constructs a new number from the first and last digit of that number and returns the difference between the original number and the number thus formed. For example: If the input is 34567 Then the corner digits number will be: 37 And the output will be: 34530 Algorithm The solution involves extracting the first and last digits, combining them to form a corner number, then calculating the difference. Example Following is the code: ...
Read MoreSimplest way to detect keypresses in JavaScript?
The simplest way to detect keypresses in JavaScript is using the onkeypress event handler. However, modern JavaScript also provides addEventListener for better event handling. document.onkeypress The key press is matched with the keyCode property, which returns the Unicode character code of the key that triggered the onkeypress event. Using document.onkeypress Keypress Detection Press any key to see the detection in action! ...
Read MoreCheck three consecutive numbers - JavaScript
We are required to write a JavaScript function that takes in a Number, say n, and we are required to check whether there exist such three consecutive natural numbers (not decimal/floating point) whose sum equals to n. If there exist such numbers, our function should return them, otherwise it should return false. Following is the code − How It Works For three consecutive numbers to sum to n, we need: x + (x+1) + (x+2) = n, which simplifies to 3x + 3 = n. Therefore, n must be divisible by 3 and greater than 5 (since ...
Read MoreConvert HTML table to array in JavaScript?
Converting an HTML table to an array in JavaScript involves extracting data from table cells and storing them in a structured format. This is commonly done using DOM manipulation methods or jQuery. HTML Table Structure Let's start with a sample HTML table: Name Age John 23 ...
Read MoreCheck if value is empty in JavaScript
In JavaScript, checking if a value is empty is essential for form validation and data processing. You can check for empty strings, null values, and undefined variables using various approaches. Basic Empty Check The most common approach is to check for empty strings and null values: Check Empty Value USERNAME: ...
Read MoreHow to capitalize the first letter of each word in a string using JavaScript?
In JavaScript, you can capitalize the first letter of each word in a string by splitting the string into individual words, capitalizing each word's first letter, and then joining them back together. Syntax string.split(' ') // Split string into array of words word.charAt(0) // Get first character word.toUpperCase() // Convert to uppercase word.substring(1) // Get ...
Read More