Object Oriented Programming Articles

Page 119 of 589

How to share private members among common instances in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 182 Views

In JavaScript, private members are variables that cannot be accessed directly from outside a constructor function or class. However, you can share private members among instances using closures and static variables. Understanding Private Members Private members are created using local variables inside constructor functions. They can only be accessed through public methods defined within the same scope. Example: Basic Private Members Private Members Example Share Private Members Among Common Instances ...

Read More

How to duplicate elements of an array in the same array with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 637 Views

Duplicating array elements means creating copies of each element within the same array. JavaScript provides several methods to achieve this, with concat() being the most straightforward approach. Using concat() Method The concat() method merges arrays and returns a new array. When you concatenate an array with itself, you effectively duplicate all elements. Duplicate Array Elements body { ...

Read More

Return the maximum number in each array using map JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 796 Views

We have an array of arrays of Numbers like this one: const arr = [ [12, 56, 34, 88], [65, 66, 32, 98], [43, 87, 65, 43], [32, 98, 76, 83], [65, 89, 32, 54], ]; We are required to write a function that maps over this array of arrays and returns an array that contains the maximum (greatest) element from each subarray. Using Math.max() with Spread Operator The most straightforward approach is to use Math.max() with the spread operator to find the maximum ...

Read More

JavaScript example to filter an array depending on multiple checkbox conditions.

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

Following is the code to filter an array depending on multiple checkbox conditions using JavaScript. This example demonstrates how to apply cumulative filters based on user checkbox selections. Example Array Filter with Multiple Checkboxes body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...

Read More

How to convert dictionary into list of JavaScript objects?

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

In JavaScript, you can convert a dictionary (object) into a list of objects using various methods. The most common approaches are Object.values(), Object.entries(), and Object.keys() with mapping. What is a Dictionary in JavaScript? A dictionary in JavaScript is typically an object with key-value pairs where values can be primitives, arrays, or other objects. Dictionary to List Conversion Convert Dictionary to List of Objects Convert Dictionary ...

Read More

Using methods of array on array of JavaScript objects?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 262 Views

JavaScript array methods work seamlessly with arrays of objects. These methods allow you to manipulate, search, and transform object arrays efficiently. Basic Array Methods on Object Arrays Common array methods like push(), pop(), and splice() work directly on arrays containing objects: Array Methods on Objects body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; ...

Read More

Explain Deep cloning an object in JavaScript with an example.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 311 Views

Deep cloning creates a completely independent copy of an object, including all nested properties. Unlike shallow copying, changes to the cloned object don't affect the original. Shallow vs Deep Copy Problem With shallow copying, nested objects are shared between original and copy: Shallow Copy Problem let original = { name: "John", ...

Read More

How to parse a string from a JavaScript array?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 269 Views

In JavaScript, you can convert an array to a string using several built-in methods. The most common approaches are toString(), join(), and JSON.stringify(). Using toString() Method The toString() method converts an array to a comma-separated string: Array to String Conversion Parse a string from a JavaScript array Convert Array to String ...

Read More

How to create an ordered array from values that have an order number in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 207 Views

When working with arrays containing values and order numbers, you often need to sort them by their order and extract just the values. This is common when dealing with image galleries, menu items, or any data that needs custom ordering. Problem Setup Let's say we have an array of strings where each string contains a file path and an order number separated by a comma: const images = [ 'photo1.jpg, 0', 'photo2.jpg, 2', 'photo3.jpg, 1' ]; console.log("Original array:", images); Original array: [ 'photo1.jpg, 0', 'photo2.jpg, ...

Read More

Explain equality of objects in JavaScript.

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 204 Views

In JavaScript, primitives like strings, numbers, and booleans are compared by their values, while objects are compared by their reference. Reference comparison checks whether two or more objects point to the same location in memory, not whether they have the same content. Reference vs Value Comparison When you compare objects with == or ===, JavaScript checks if they reference the same object in memory, not if their properties are identical. Object Equality Object ...

Read More
Showing 1181–1190 of 5,881 articles
« Prev 1 117 118 119 120 121 589 Next »
Advertisements