Front End Technology Articles

Page 379 of 652

How to check whether an array is a true array in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 245 Views

In JavaScript, arrays are actually objects, which makes type checking tricky. When you use the typeof operator on an array, it returns "object" rather than "array", making it unreliable for array detection. The Problem with typeof The typeof operator cannot distinguish between arrays and plain objects since both return "object". Syntax typeof operand Parameters: The typeof operator takes an operand and returns a string indicating the data type of the operand. Example: typeof with Arrays and Objects var a = [1, 2, 5, ...

Read More

Joining two strings with two words at a time - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 219 Views

We are required to write a JavaScript function that takes in two strings, creates and returns a new string with first two characters of first string, next two characters of second string, then first, then second and so on. For example: If the strings are: const str1 = 'Hello world'; const str2 = 'How are you btw'; Then the output should be: 'HeHollw o arwoe rlyodu btw' Approach The algorithm alternates between the two strings, taking two characters at a time. When one string is exhausted, it appends the ...

Read More

How to access nested json objects in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 15K+ Views

Accessing nested JSON objects in JavaScript involves navigating through multiple levels of object properties. Nested objects are objects contained within other objects, creating a hierarchical data structure. What are Nested JSON Objects? A nested JSON object has one or more objects as property values. This creates multiple layers that you need to traverse to access specific data. Using Dot Notation The most common way to access nested properties is using dot notation, where you chain property names with dots. Example 1: Single Level Nesting var person = ...

Read More

Converting a proper fraction to mixed fraction - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 543 Views

A proper fraction is one where the numerator is smaller than the denominator, represented in p/q form where both p and q are natural numbers. What is a Mixed Fraction? When we divide the numerator (a) of a fraction by its denominator (b), we get a quotient (q) and remainder (r). The mixed fraction form for fraction a/b is: Mixed form: q r b This is pronounced as "q wholes and r by b". Problem Statement We need to write a ...

Read More

How to modify properties of a nested object in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 3K+ Views

There are two methods to modify properties of nested objects in JavaScript. One is Dot notation and the other is Bracket notation. The functionality is the same for both methods, but they differ in their syntax and use cases. Let's discuss them in detail with practical examples. Dot Notation Method Dot notation is the most common way to access and modify nested object properties. Use this when property names are valid identifiers and known at compile time. Example In the following example, initially the value of property country is England. Using dot notation, the value ...

Read More

Implementing Priority Sort in JavaScript

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

We are required to write a JavaScript function that takes in two arrays of numbers, second being smaller in size than the first. Our function should return a sorted version of the first array (in increasing order) but put all the elements that are common in both arrays to the front. For example − If the two arrays are − const arr1 = [5, 4, 3, 2, 1]; const arr2 = [2, 3]; Then the output should be − [2, 3, 1, 4, 5] How It Works The priority ...

Read More

How to find duplicates in an array using set() and filter() methods in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 1K+ Views

Finding duplicates in JavaScript arrays is a common task that can be accomplished using modern JavaScript methods. The Set() constructor and filter() method provide elegant solutions for removing duplicates without complex logic. Using Set() Method The Set() constructor automatically stores only unique values, making duplicate removal straightforward. When combined with the spread operator, it creates a new array with duplicates removed. Syntax let uniqueArray = [...new Set(originalArray)]; Example var dupNames = ['John', 'Ram', 'Rahim', 'Remo', 'Ram', 'Rahim']; var uniArr = [...new ...

Read More

Finding mistakes in a string - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 542 Views

We are required to write a JavaScript function that takes in two strings. The first string is some mistyped string and the second string is the correct version of this string. We can assume that the two strings we are getting as argument will always have the same length. We have to return the number of mistakes that exist in the first string by comparing it character by character with the correct version. Approach The solution involves iterating through both strings simultaneously and comparing each character at the same position. When characters don't match, we increment our ...

Read More

How to hide/show HTML elements in JavaScript?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 2K+ Views

JavaScript provides several ways to hide and show HTML elements by manipulating their CSS properties. The most common approach is using the display property with values like none (to hide) and block (to show). Hiding an Element To hide an element, set its display property to none. This removes the element from the document flow completely. Example In the following example, clicking the "Hide Me" button hides the paragraph text: Using JavaScript to hide HTML elements. Showing an Element ...

Read More

Frequency distribution of elements - JavaScript

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

We are required to write a JavaScript function that takes a string and returns an object representing the frequency distribution of each character in the string. const str = 'This string will be used to calculate frequency distribution'; We need to return an object that represents the frequency distribution of various characters present in the string. Example Following is the code: const str = 'This string will be used to calculate frequency distribution'; const frequencyDistribution = str => { const map = {}; ...

Read More
Showing 3781–3790 of 6,519 articles
« Prev 1 377 378 379 380 381 652 Next »
Advertisements