Javascript Articles

Page 473 of 534

How do I check whether a checkbox is checked in jQuery?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 370 Views

To check whether a checkbox is checked in jQuery, you can use several methods. The most common approaches are using the .is(':checked') method, the .prop('checked') method, or implementing toggle functionality. Method 1: Using .is(':checked') The .is(':checked') method returns a boolean value indicating whether the checkbox is checked: Checkbox Check Example Check me Check Status ...

Read More

Concatenate two arrays of objects and remove repeated data from an attribute in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 291 Views

When concatenating two arrays of objects, you often need to remove duplicates based on a specific attribute. This article demonstrates how to merge arrays while handling duplicate entries using map() and find() methods. The Challenge Consider two arrays of product objects where some products appear in both arrays with different properties. We want to concatenate them but prioritize data from the second array when duplicates exist. Example: Merging Product Arrays Let's merge two product arrays and remove duplicates based on productId: var details1 = [ { ...

Read More

Get the first element of array in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 1K+ Views

In JavaScript, there are several ways to get the first element of an array. The most common and efficient approaches include using bracket notation, the at() method, or destructuring assignment. Using Bracket Notation (Most Common) The simplest way is to access the element at index 0 using bracket notation: let fruits = ["apple", "banana", "orange"]; let firstFruit = fruits[0]; console.log(firstFruit); // Handle empty arrays let emptyArray = []; let firstElement = emptyArray[0]; console.log(firstElement); apple undefined Using the at() Method The at() method provides a modern alternative for accessing array ...

Read More

How to use my object like an array using map function in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 179 Views

JavaScript objects aren't arrays, so they don't have array methods like map(). However, you can use Object.keys(), Object.values(), or Object.entries() to convert object data into arrays, then apply map(). Using Object.keys() with map() Extract object keys as an array, then use map() to iterate: const object = { name: 'John', age: 21, countryName: 'US', subjectName: 'JavaScript' }; const allKeys = Object.keys(object); console.log("All keys:", allKeys); // Using map to get values from keys const mappedValues = allKeys.map(key => object[key]); ...

Read More

Changing value of nested object keys in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 683 Views

In JavaScript, you can change nested object values using dot notation and square brackets. This is useful when working with complex data structures containing multiple levels of nesting. Syntax // Using dot notation object.property.nestedProperty = newValue; // Using square brackets object['property']['nestedProperty'] = newValue; // Mixed approach object.property['nestedProperty'] = newValue; Example: Changing Nested Object Values var details = { "customer": { "customerDetails": { "otherDetails": [ ...

Read More

Display all the values of an array in p tag on a web page with JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 814 Views

In JavaScript, you can display array values as paragraph elements on a web page using several approaches. Here are the most common methods without requiring external libraries. Method 1: Using forEach() with createElement Display Array Values const arrayValues = [1000000001, "John", "Smith", 100, 200, 3000]; const container ...

Read More

Child node count in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 760 Views

In JavaScript, you can get the count of child elements using the children.length property. This property returns the number of direct child elements, excluding text nodes and comments. Syntax element.children.length Example: Counting Child Elements Child Node Count Example List Of Subject Names are as follows: Javascript MySQL ...

Read More

Set scroll view with intervals in JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 769 Views

Setting a scroll view with intervals in JavaScript allows you to automatically scroll content and add new elements at regular time intervals. This technique uses scrollTop and scrollHeight properties along with setInterval(). Key Properties The main properties for controlling scroll behavior are: scrollTop - Gets or sets the number of pixels scrolled from the top scrollHeight - Returns the total height of scrollable content Example Auto Scroll with Intervals ...

Read More

Regex - reusing patterns to capture groups in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 584 Views

Regular expressions can use backreferences to capture groups and reuse them later in the pattern. The syntax \1, \2, etc., refers to previously captured groups. How Backreferences Work When you create a group with parentheses (), the regex engine remembers the matched content. You can reference this captured content later using \1 for the first group, \2 for the second, and so on. Syntax /^(pattern1)(pattern2)\1\2$/ // \1 matches the same text as the first group // \2 matches the same text as the second group Example: Matching Repeated Patterns var groupValues1 ...

Read More

Not able to push all elements of a stack into another stack using for loop in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 319 Views

When transferring elements from one stack to another using a for loop, you need to understand that the stack follows the Last In First Out (LIFO) principle. The key is to pop() elements from the source stack and push() them into the destination stack. The Stack Transfer Process When you pop elements from the first stack and push them into the second stack, the order gets reversed because of the LIFO nature: var myFirstStack = [10, 20, 30, 40, 50, 60, 70]; var mySecondStack = []; console.log("Original first stack:", myFirstStack); console.log("Original second stack:", mySecondStack); ...

Read More
Showing 4721–4730 of 5,340 articles
« Prev 1 471 472 473 474 475 534 Next »
Advertisements