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
Articles by AmitDiwan
Page 449 of 840
Multi-selection of Checkboxes on button click in jQuery?
Multi-selecting checkboxes is a common requirement in web forms. This can be achieved using jQuery to toggle all checkboxes with a single button click. Approach We'll use jQuery's prop() method to set the checked property of multiple checkboxes and toggleClass() to manage the button state. Example Multi-selection Checkboxes .changeColor { ...
Read MoreReturning the second most frequent character from a string (including spaces) - JavaScript
We are required to write a JavaScript function that takes in a string and returns the character which makes second most appearances in the string. Approach The solution involves counting character frequencies, sorting them by frequency, and returning the second most frequent character. Here's how it works: Create a frequency map to count each character occurrence Convert the map to an array of [character, frequency] pairs Sort the array by frequency in descending order Return the character at index 1 (second position) ...
Read MoreCreating an array using a string which contains the key and the value of the properties - JavaScript
Suppose, we have a special kind of string like this − const str = "Integer, 1 Float, 2.0Boolean, True Integer, 6Float, 3.66 Boolean, False"; We are required to write a JavaScript function that converts the above string into an array of objects, using the String.prototype.split() method − const arr = [ { "Integer": 1, "Float": 2.0 }, { ...
Read MoreHow to create a unique ID for each object in JavaScript?
In JavaScript, creating unique IDs for objects is essential for tracking and identifying instances. The most reliable method is using Symbol(), which generates guaranteed unique identifiers. Using Symbol() for Unique IDs The Symbol() function creates a unique symbol every time it's called, even with the same description. This makes it perfect for generating unique object identifiers. Unique Object IDs body { ...
Read MoreRemove values in an array by comparing the items 0th index in JavaScript?
When working with arrays of sub-arrays, you may need to remove duplicates based on the first element (0th index) of each sub-array. This is common when dealing with data like subject-marks pairs where you want only unique subjects. Let's say the following is our array: var subjectNameAlongWithMarks = [ ["JavaScript", 78], ["Java", 56], ["JavaScript", 58], ["MySQL", 77], ["MongoDB", 75], ["Java", 98] ]; console.log("Original array:", subjectNameAlongWithMarks); Original array: [ ...
Read MoreFiguring out the highest value through a for in loop - JavaScript
When working with comma-separated strings in JavaScript, you might need to find which value appears most frequently. This tutorial demonstrates how to use a for-in loop to count occurrences and determine the most frequent item. Suppose we have a comma-separated string containing fruit names: const str = 'Banana, Banana, Pear, Orange, Apple, Melon, Grape, Apple, Banana, Grape, Melon, Grape, Melon, Apple, Grape, Banana, Orange, Melon, Orange, Banana, Banana, Orange, Pear, Grape, Orange, Orange, Apple, Apple, Banana'; console.log(str); Banana, Banana, Pear, Orange, Apple, Melon, Grape, Apple, Banana, Grape, Melon, Grape, Melon, Apple, Grape, Banana, Orange, ...
Read MoreHow to access an object through another object in JavaScript?
In JavaScript, you can access properties and methods of one object from another object by referencing them directly. This technique is useful for sharing data between objects or creating relationships. Basic Property Access The simplest way is to reference properties directly from another object: Object Access Example CLICK HERE // First object with properties and method let obj = { firstName: "Rohan", lastName: "Sharma", welcome() { ...
Read MoreAlternatively merging two arrays - JavaScript
We are required to write a JavaScript function that takes in two arrays and merges the arrays taking elements alternatively from the arrays. For example, if the two arrays are: const arr1 = [4, 3, 2, 5, 6, 8, 9]; const arr2 = [2, 1, 6, 8, 9, 4, 3]; Then the output should be: const output = [4, 2, 3, 1, 2, 6, 5, 8, 6, 9, 8, 4, 9, 3]; Method 1: Using Index-Based Logic This approach uses a single loop and alternates between arrays based on even/odd ...
Read MoreHow to create a multidimensional JavaScript object?
A multidimensional JavaScript object is an object that contains other objects as properties, creating nested structures. This allows you to organize complex data hierarchically. Basic Syntax let multidimensionalObject = { property1: "value1", property2: { nestedProperty1: "nestedValue1", nestedProperty2: { deeplyNestedProperty: "deeplyNestedValue" } } }; Example: Creating a Student ...
Read MoreHow to avoid inserting NULL values to a table with JavaScript?
When building dynamic tables with JavaScript, it's important to validate user input and prevent NULL values from being inserted. This ensures data integrity and provides a better user experience. Understanding NULL Validation In JavaScript, we need to check for null, undefined, and empty strings before inserting values into a table. The basic condition structure is: while (!(variable1 == null || variable2 == null || variable3 == null)) { // Insert values only when none are null } Complete Example with Validation ...
Read More