Object Oriented Programming Articles

Page 172 of 589

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

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 193 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 689 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 827 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 766 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 782 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 594 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 338 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

How to make my textfield empty after button click in JavaScript?

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

To clear a text field after a button click in JavaScript, you can use the onclick event with document.getElementById().value = '' to reset the input field's value to an empty string. Syntax document.getElementById("fieldId").value = ''; Example Clear Text Field Example Clear Text function clearTextField() { ...

Read More

How can we invoke the parent's method, when a child has a method with the same name in JavaScript?

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

When both parent and child classes have methods with the same name, JavaScript provides several ways to invoke the parent's method from the child class or externally. Syntax To call a parent method when overridden by a child class: // From within child class super.methodName() // From outside using call() ParentClassName.prototype.methodName.call(childObject) Using super Keyword (Recommended) The super keyword is the modern way to call parent methods from within a child class: class Parent { constructor(value) { this.value = ...

Read More

Display the dropdown's (select) selected value on console in JavaScript?

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

In JavaScript, you can capture the selected value from a dropdown (select element) and display it in the console using the onchange event and console.log(). HTML Structure Here's a basic dropdown with an onchange event handler: Javascript MySQL MongoDB Java Complete Example Dropdown Selected Value Select a Subject: ...

Read More
Showing 1711–1720 of 5,881 articles
« Prev 1 170 171 172 173 174 589 Next »
Advertisements