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 on Trending Technologies
Technical articles with clear explanations and examples
Single dimensional array vs multidimensional array in JavaScript.
JavaScript supports both single-dimensional and multidimensional arrays. A single-dimensional array stores elements in a linear sequence, while a multidimensional array contains arrays as elements, creating a matrix-like structure. Single-Dimensional Arrays A single-dimensional array is a simple list of elements accessed by a single index. Single Dimensional Array let singleArray = [10, 20, 30, 40, 50]; console.log("Single-dimensional array:", ...
Read MoreHow to selectively retrieve value from json output JavaScript
We have the following data inside a JSON file data.json: data.json { "names": [{ "name": "Ramesh", "readable": true }, { "name": "Suresh", "readable": false }, { "name": "Mahesh", "readable": true }, { "name": "Gourav", "readable": true }, { "name": "Mike", "readable": false }] } ...
Read MoreCan JavaScript parent and child classes have a method with the same name?
Yes, JavaScript parent and child classes can have methods with the same name. This concept is called method overriding, where the child class provides its own implementation of a method that already exists in the parent class. Method Overriding Example class Parent { constructor(parentValue) { this.parentValue = parentValue; } // Parent class method showValues() { console.log("The parent method is called....."); ...
Read MoreMapping unique characters of string to an array - JavaScript
We are required to write a JavaScript function that takes in a string and starts mapping its characters from 0. Every time the function encounters a unique (non-duplicate) character, it should increase the mapping count by 1, otherwise map the same number for duplicate characters. For example, if the string is: const str = 'heeeyyyy'; Then the output should be: const output = [0, 1, 1, 1, 2, 2, 2, 2]; How It Works The algorithm works by tracking consecutive character groups. When a character differs from the previous one, ...
Read MoreFinding reversed index of elements in arrays - JavaScript
We need to create a JavaScript function that finds the reversed index of an element in an array without actually reversing it. This function calculates what position an element would occupy if the array were reversed. If the element is not present in the array, the function returns -1. Otherwise, it returns the index position the element would have in a reversed array. Understanding Reversed Index The reversed index is calculated using the formula: length - originalIndex - 1 For example, in array [45, 74, 34, 32, 23, 65]: Element 23 is at index 4 ...
Read MoreHow to add an element in the last of a JavaScript array?
In this tutorial, we will learn how to add an element to the last of a JavaScript array. The most common method to add an element to the end of the array is by using the Array push() method, but we will discuss multiple methods to achieve this. Using the Array.prototype.push() Method Using the Array.prototype.splice() Method Using Array Indexing Using the Array.prototype.push() Method To add an element at the end, use the JavaScript push() method. The push() method appends the given element(s) to the end of the array and ...
Read MoreHow to get the value of PI in JavaScript?
In this tutorial, we will learn how to get the value of PI in JavaScript. The PI is a mathematical constant that is widely used in different sections of mathematics. It is defined by the ratio of the circumference of a circle to its diameter, which is approximately 3.14159. It is represented by the symbol '𝜋', which is a Greek letter. The value of PI is an irrational number, which means the value of the PI can't be expressed as a fraction, and the digits that came after the decimal are non-terminating and non-repeating. The value ...
Read MoreHow can we use a JavaScript function as an object?
This tutorial will teach us to use JavaScript functions as objects. In JavaScript, functions are first-class objects, meaning they can have properties and methods just like regular objects. This powerful feature allows us to create constructor functions that act as blueprints for creating multiple similar objects. The JavaScript object is an entity that contains key-value pairs with unique keys. Each key has values that can be of any type. We can access object values using their keys. We can create a function that behaves like an object using the this keyword and the new operator. Below is a ...
Read MoreHow to set the widths of the image border with JavaScript?
In this tutorial, we shall learn to set the widths of the image border with JavaScript. To set the widths of the image border, use the borderImageWidth property in JavaScript. When we need an image as a border of our webpage content, we have to see how to set the width of the image border. Using the Style borderImageWidth Property With the Style borderImageWidth property, we can set or return the widths of the image border of an element. The border image will range beyond the padding when the border image width is greater than the ...
Read MoreHow to set the position of the list-item marker with JavaScript?
To set the position of the marker of the list-item, use the listStylePosition property in JavaScript. This property determines whether the list marker appears inside or outside the list item's content flow. Syntax element.style.listStylePosition = "inside" | "outside" | "inherit"; Parameters Value Description inside Marker is positioned inside the list item's content box outside Marker is positioned outside the list item's content box (default) inherit Inherits the value from parent element Example: Interactive List Position ...
Read More