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 172 of 589
How to use my object like an array using map function in JavaScript?
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 MoreChanging value of nested object keys in JavaScript
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 MoreDisplay all the values of an array in p tag on a web page with JavaScript
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 MoreChild node count in JavaScript?
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 MoreSet scroll view with intervals in JavaScript
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 MoreRegex - reusing patterns to capture groups in JavaScript?
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 MoreNot able to push all elements of a stack into another stack using for loop in JavaScript?
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 MoreHow to make my textfield empty after button click in JavaScript?
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 MoreHow can we invoke the parent's method, when a child has a method with the same name in JavaScript?
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 MoreDisplay the dropdown's (select) selected value on console in JavaScript?
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