Javascript Articles

Page 414 of 534

First element and last element in a JavaScript array?

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

An array is a group of elements where each element has its own index value. We can access any element using these indexes. For the first element, the index is always 0, but for the last element, we need to use the array's length property to calculate the correct index. Accessing the First Element Since arrays are zero-indexed in JavaScript, the first element is always at index 0. If the array is arr, then the first element is arr[0]. Example In the following example, we have two arrays and we'll access their first elements using index ...

Read More

Execute digits in even places in a JavaScript array?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 212 Views

In JavaScript, extracting elements from even positions in an array requires understanding that array indexing starts from 0. Elements at even positions are at indices 0, 2, 4, etc., while elements at odd positions are at indices 1, 3, 5, etc. To extract elements from even positions, we can use various methods like filter(), traditional loops, or specific iteration patterns. Understanding Array Positions JavaScript arrays are zero-indexed, meaning: Even positions: indices 0, 2, 4, 6... Odd positions: indices 1, 3, 5, 7... Using the filter() Method The filter() method creates a new array ...

Read More

Super keyword in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 1K+ Views

In this article, we are going to discuss about the super keyword in JavaScript with suitable examples. The super keyword is used in JavaScript classes to access properties and methods of a parent class from a child class. It's essential for implementing proper inheritance in object-oriented programming. When a child class and parent class have methods with the same names, the super keyword helps distinguish between them. The child class must extend the parent class using the extends keyword to use super. Syntax The syntax to represent the super keyword is: super(arguments); ...

Read More

How to generate a random number in JavaScript?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 2K+ Views

JavaScript's Math.random() method is the built-in way to generate random numbers. It returns a floating-point number between 0 (inclusive) and 1 (exclusive), which can be scaled to any desired range. The Math.random() function returns a pseudo-random number in the range [0, 1) with uniform distribution. The implementation generates the seed automatically, and users cannot modify it. Basic Math.random() Usage Syntax Math.random() Return Value A floating-point, pseudo-random number between 0 (inclusive) and 1 (exclusive). Example Random Number Generation ...

Read More

JavaScript's Boolean function?

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

The Boolean() function in JavaScript converts any value to its boolean equivalent (true or false). This is useful for conditional checks and validation in your applications. Syntax Boolean(value); It takes any value or expression and returns true for truthy values and false for falsy values. Falsy Values These values always return false when converted to boolean: console.log(Boolean(0)); // false console.log(Boolean("")); // false (empty ...

Read More

How to access a JavaScript object using its own prototype?

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

JavaScript's Object.create() method creates a new object with the specified object as its prototype. This allows the new object to inherit properties from the existing object while maintaining a prototype chain. Syntax Object.create(prototypeObject); This method takes an existing object and creates a new object that inherits properties from it through the prototype chain. How It Works When you create an object using Object.create(), the new object doesn't copy the properties directly. Instead, it creates a prototype link to the original object, allowing property inheritance. var ...

Read More

Why is using "for...in" loop in JavaScript array iteration a bad idea?

Manisha Patil
Manisha Patil
Updated on 15-Mar-2026 305 Views

The for...in loop in JavaScript is designed for iterating over object properties, not array elements. Using it for arrays can lead to unexpected behavior and performance issues. Main Problems with for...in on Arrays There are several critical issues when using for...in loops with arrays: Prototype pollution: If Array.prototype is modified, for...in will iterate over inherited properties, not just array elements. No guaranteed order: for...in doesn't guarantee that array elements will be processed in numerical order. Performance overhead: The loop checks the entire prototype chain, making it slower ...

Read More

w vs W in JavaScript regex?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 4K+ Views

In JavaScript regex, \w and \W are complementary metacharacters used to match different types of characters. \w matches word characters (letters, digits, and underscores), while \W matches non-word characters (everything else). Understanding \w Metacharacter The \w metacharacter is equivalent to [a-zA-Z0-9_], matching any single letter (uppercase or lowercase), digit, or underscore. Syntax // Using RegExp constructor RegExp("\w", "g") // Using literal notation /\w/g Example: Using \w to Match Word Characters \w vs \W in JavaScript regex \w Metacharacter Example ...

Read More

d vs D in JavaScript?

Lokesh Yadav
Lokesh Yadav
Updated on 15-Mar-2026 3K+ Views

In JavaScript regular expressions, \d and \D are metacharacters used to match different types of characters in strings. Understanding their differences is essential for effective pattern matching. \d matches any single digit character (equivalent to [0-9]), while \D matches any character that is NOT a digit (equivalent to [^0-9]). These metacharacters are complete opposites of each other. Syntax Both metacharacters can be used in two ways: // Using RegExp constructor new RegExp("\d", "g") // matches digits new RegExp("\D", "g") // matches non-digits // Using regex literal /\d/g ...

Read More

Regular functions vs Arrow functions in JavaScript?

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

Arrow functions and regular functions are both ways to define functions in JavaScript, but they have important differences in behavior. Understanding these differences helps you choose the right function type for your needs. Syntax The syntax differs between regular and arrow functions: Arrow Function Syntax let x = (params) => { // code }; Regular Function Syntax let x = function functionName(params) { // code }; Usage of "this" Keyword The most significant difference is how they handle the this ...

Read More
Showing 4131–4140 of 5,340 articles
« Prev 1 412 413 414 415 416 534 Next »
Advertisements