Javascript Articles

Page 408 of 534

How to convert a string to a floating point number in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 2K+ Views

In JavaScript, converting a string to a floating point number is a common task that can be accomplished through several methods. This article explores three effective approaches to achieve this conversion. Using the parseFloat() Method The parseFloat() function is the most direct way to convert a string to a floating point number. It parses a string and returns the first number found, including decimal values. Syntax parseFloat(string) Note: If the first character cannot be converted to a number, parseFloat() returns NaN. Example: Basic parseFloat() Usage ...

Read More

Is it possible to change the HTML content in JavaScript?

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

Yes, it is possible to change HTML content using JavaScript. JavaScript provides DOM (Document Object Model) methods that can access and modify HTML elements. These methods, such as document.getElementById(), document.getElementsByTagName(), and others, allow you to dynamically update content in HTML tags like , , , etc. Common Methods to Change HTML Content The most frequently used properties for changing HTML content are: innerHTML - Changes the HTML content inside an element textContent - Changes only the text content (no HTML tags) innerText - Similar to textContent but respects styling Example 1: Changing Content with ...

Read More

What is the use of _.size() method in JavaScript?

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

The _.size() method is part of the Underscore.js library and returns the number of elements in arrays, objects, and strings. It provides a consistent way to get the size of various data types. Syntax _.size(collection) Parameters collection: The array, object, or string to count elements from. Return Value Returns a number representing the count of elements in the collection. Example 1: Array Size Find the size of a numeric array using _.size(): var arr = [100, 62, 73, 534, 565]; document.write("Array size: ...

Read More

What is the importance of _.initial() function in JavaScript?

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

The _.initial() function is part of the Underscore.js library that returns all elements of an array except the last n elements. It's useful for removing elements from the end of an array without modifying the original array. Syntax _.initial(array, n); Parameters array - The input array from which to extract elements. n (optional) - Number of elements to exclude from the end. Default is 1. Return Value Returns a new array containing all elements except the last n elements. Example: Basic Usage ...

Read More

How to remove the 0th indexed element in an array and return the rest of the elements in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 956 Views

Arrays in JavaScript are zero-indexed data structures where elements can be accessed using their index positions. The first element is at index 0, the second at index 1, and so on. const colors = ["Green", "Maroon", "Blue"]; // Index: 0 1 2 This article explores different methods to remove the first element (at index 0) from an array and return the remaining elements. Using the shift() Method The shift() method removes the first element from an array ...

Read More

How to find the common elements between two or more arrays in JavaScript?

Nikhilesh Aleti
Nikhilesh Aleti
Updated on 15-Mar-2026 10K+ Views

In JavaScript, finding common elements between two or more arrays is a frequent requirement in web development. Arrays are objects that store multiple values, and there are several efficient methods to identify shared elements across them. Using for Loop The traditional approach uses nested for loops to compare each element of one array with every element of another array. This method works by creating an empty array and pushing matching elements into it. Example 1 Here's how to find common elements between two numeric arrays: Common elements between ...

Read More

How to get the first n values of an array in JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 1K+ Views

In JavaScript, getting the first n elements from an array is a common operation. There are several built-in methods to accomplish this efficiently. First n values means extracting elements from index 0 to index n-1. For example, if n=3, you get elements at positions 0, 1, and 2. Using the slice() Method (Recommended) The slice() method is the most common and efficient way to get the first n elements. It creates a new array without modifying the original. Syntax array.slice(0, n) Example 1: Basic Usage ...

Read More

How to invert an object in JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 3K+ Views

Inverting an object in JavaScript means swapping its keys and values, so that {name: "John", age: 25} becomes {"John": "name", "25": "age"}. This is useful for creating lookup tables or reverse mappings. There are several ways to invert objects in JavaScript, from using libraries like Underscore.js to native JavaScript methods. Using Underscore.js _.invert() The _.invert() function from Underscore.js provides a simple way to swap object keys and values. Syntax _.invert(object) Parameters: object − The object to invert Return Value: A new object with keys and values ...

Read More

What is the relation between 'null' and '0' in JavaScript?

Aman Kumar
Aman Kumar
Updated on 15-Mar-2026 4K+ Views

In JavaScript, the relationship between null and 0 creates a seemingly contradictory behavior that confuses many developers. While null is neither greater than nor equal to 0 in equality checks, it evaluates as greater than or equal to 0 in comparison operations. Understanding null and 0 null is a primitive value representing an intentional absence of value, while 0 is a number. The confusing behavior occurs due to JavaScript's type coercion rules, which differ between equality (==) and comparison (>, =,

Read More

How to remove the last digit of a number and execute the remaining digits in JavaScript?

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

In JavaScript, you can remove the last digit from a number using different approaches. The most common methods involve string manipulation or mathematical operations like bitwise operations. When working with numbers, you typically need to convert the number to a string to use string methods, or use mathematical operations to avoid type conversion altogether. Method 1: Using String substring() The substring() method extracts characters from a string between two specified indices. Syntax str.substring(startIndex, endIndex) To remove the last digit, use str.substring(0, str.length - 1) where the first parameter is the starting index ...

Read More
Showing 4071–4080 of 5,340 articles
« Prev 1 406 407 408 409 410 534 Next »
Advertisements