Articles on Trending Technologies

Technical articles with clear explanations and examples

Is it possible to have JavaScript split() start at index 1?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 404 Views

The built-in String.prototype.split() method doesn't have a parameter to start splitting from a specific index. However, we can combine split() with array methods like slice() to achieve this functionality. Problem with Standard split() The standard split() method always starts from index 0 and splits the entire string: const text = "The quick brown fox jumped over the wall"; console.log(text.split(" ")); [ 'The', 'quick', 'brown', 'fox', 'jumped', 'over', 'the', 'wall' ] Method 1: Using split() with slice() The simplest ...

Read More

Display a message on console while focusing on input type in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 317 Views

In JavaScript, you can display console messages when focusing on input elements using the focus and blur event listeners. This is useful for debugging form interactions and tracking user behavior. Basic Focus Event Example The focus event triggers when an input element receives focus, while blur triggers when it loses focus: Focus Console Messages Submit ...

Read More

Splitting strings based on multiple separators - JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 670 Views

We are required to write a JavaScript function that takes in a string and any number of characters specified as separators. Our function should return a splitted array of the string based on all the separators specified. For example, if the string is: const str = 'rttt.trt/trfd/trtr, tr'; And the separators are: const sep = ['/', '.', ', ']; Then the output should be: const output = ['rttt', 'trt', 'trfd', 'trtr']; Method 1: Using Manual Iteration This approach manually iterates through each character and checks if ...

Read More

How to return a string representing the source for an equivalent Date object?

Daniol Thomas
Daniol Thomas
Updated on 15-Mar-2026 150 Views

The toSource() method was a non-standard JavaScript method that returned a string representing the source code of a Date object. However, this method has been deprecated and removed from modern browsers. The Deprecated toSource() Method The toSource() method was originally available in Firefox but was never part of the ECMAScript standard. It would return a string that could theoretically recreate the Date object: // This method is deprecated and no longer works var dt = new Date(2018, 0, 15, 14, 39, 7); // dt.toSource() would have returned: (new Date(1516022347000)) Modern Alternatives Since toSource() ...

Read More

What is to be done when text overflows the containing element with JavaScript?

Krantik Chavan
Krantik Chavan
Updated on 15-Mar-2026 164 Views

When text overflows its container, JavaScript can help control the display behavior using the textOverflow property. This property works with CSS to handle overflow gracefully by adding ellipses or clipping the text. CSS Requirements For textOverflow to work properly, the element must have these CSS properties: overflow: hidden - Hide overflowing content white-space: nowrap - Prevent text wrapping Fixed width - Constrain the container size JavaScript textOverflow Values The textOverflow property accepts these values: "clip" - Cut off text at container edge "ellipsis" - Show "..." where text is cut "visible" ...

Read More

How to set the cases for a text in CSS?

Samual Sam
Samual Sam
Updated on 15-Mar-2026 285 Views

The text-transform property in CSS allows you to control the capitalization of text without modifying the original HTML content. This property is particularly useful for styling headings, navigation links, and other text elements consistently across your website. Syntax text-transform: none | capitalize | uppercase | lowercase | initial | inherit; Property Values The text-transform property accepts the following values: none - No transformation (default value) capitalize - First letter of each word is capitalized uppercase - All letters are converted ...

Read More

Looping through an array in Javascript

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

Arrays are linear data structures that store multiple elements in an ordered collection. Each element can be accessed using its index number, starting from 0. const array_name = [item1, item2, ...]; const movies = ["Bahubali", "RRR", "KGF", "Pushpa"]; // Index values: // Bahubali – [0] // RRR – [1] // KGF – [2] // Pushpa – [3] Loops are programming constructs that execute a sequence of instructions repeatedly until a specified condition is met. They're essential for iterating through arrays efficiently. Traditional for Loop The for loop provides complete control over initialization, condition, ...

Read More

ArrayBuffer.slice() function in JavaScript

Samual Sam
Samual Sam
Updated on 15-Mar-2026 600 Views

The ArrayBuffer object in JavaScript represents a fixed-length binary data buffer. The slice() method creates a new ArrayBuffer containing a copy of the specified portion of the original buffer. Syntax arrayBuffer.slice(start, end) Parameters start (optional): The byte index where the slice begins (inclusive). Defaults to 0. end (optional): The byte index where the slice ends (exclusive). Defaults to buffer length. Return Value Returns a new ArrayBuffer containing the copied bytes from the specified range. Example: Basic ArrayBuffer Slicing ArrayBuffer Slice Example ...

Read More

How do I search through an array using a string, which is split into an array with JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 279 Views

We are given an array of strings and another string for which we are required to search in the array. We can filter the array checking whether it contains all the characters that user provided through the input. Using Array Filter with Split (Flexible Search) This approach splits the search string into parts and checks if each part exists in the array elements, regardless of order. const deliveries = ["14/02/2020, 11:47, G12, Kalkaji", "13/02/2020, 11:48, A59, Amar Colony"]; const input = "g12, kal"; const pn = input.split(" "); const requiredDeliveries = deliveries.filter(delivery => ...

Read More

JavaScript creating an array from JSON data?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 986 Views

To create an array from JSON data in JavaScript, you can use the map() method to extract specific values from each object. This is particularly useful when working with API responses or complex data structures. Basic JSON Data Structure Let's start with a simple JSON array containing student information: const studentDetails = [ { name: "John" }, { name: "David" }, ...

Read More
Showing 16701–16710 of 61,297 articles
Advertisements