Articles on Trending Technologies

Technical articles with clear explanations and examples

JavaScript Regex to remove text after a comma and the following word?

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Mar-2026 942 Views

When working with strings in JavaScript, you might encounter scenarios where you need to clean or format text by removing specific portions. A common task is to remove text after a comma and the following word. This can be achieved efficiently using JavaScript Regular Expressions (Regex). In this article, we'll show you how to do it step-by-step. Why Use Regex for Text Manipulation? Regex, short for Regular Expressions, is a powerful tool for pattern matching and text processing. It allows you to identify and manipulate text patterns with precision, making tasks like cleaning data or reformatting strings much ...

Read More

Repeating letter string - JavaScript

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

We are required to write a JavaScript function that takes in a string and a number, say n, and the function should return a new string in which all the letters of the original string are repeated n times. For example: If the string is − const str = 'how are you' And the number n is 2 Then the output should be − const output = 'hhooww aarree yyoouu' Example Following is the code − const str = 'how are you'; const repeatNTimes ...

Read More

How I can show JavaScript alert box in the middle of the screen?

Giri Raju
Giri Raju
Updated on 15-Mar-2026 2K+ Views

The native JavaScript alert() box cannot be repositioned as its styling and position are controlled by the browser. To show an alert box in the center of the screen, you need to create a custom alert dialog using HTML, CSS, and JavaScript. Why Native alert() Can't Be Centered The built-in alert() function displays a browser-controlled modal that appears at a fixed position determined by the browser, typically near the top of the viewport. This position cannot be customized through CSS or JavaScript. Creating a Custom Centered Alert Box Here's how to create a custom alert that ...

Read More

How to select multiple options in a dropdown list with JavaScript?

Prabhdeep Singh
Prabhdeep Singh
Updated on 15-Mar-2026 12K+ Views

In JavaScript, you can enable multiple selection in a dropdown list by setting the multiple property to true. This allows users to select multiple options by holding Ctrl (Windows) or Cmd (Mac) while clicking. Syntax function enableMultipleSelection() { document.getElementById("selectId").multiple = true; } How It Works The multiple property controls whether a select element allows multiple selections. When set to true, users can select multiple options using keyboard modifiers: Ctrl + Click (Windows/Linux) to select multiple individual options Cmd + Click (Mac) to select multiple individual options Shift + Click ...

Read More

Does it make sense to use HTML comments on blocks of JavaScript?

Sravani Alamanda
Sravani Alamanda
Updated on 15-Mar-2026 283 Views

No, it does not make sense to use HTML comments on blocks of JavaScript in modern web development. HTML comments within JavaScript were a workaround used in the 1990s to hide JavaScript code from very old browsers that didn't understand the tag. Since all modern browsers support JavaScript, this practice is obsolete and not recommended. Historical Context: Why HTML Comments Were Used In the early days of JavaScript (1995), browsers like Netscape 1 didn't support the tag. Without HTML comments, these browsers would display JavaScript code as plain text on the webpage. The HTML comment syntax ...

Read More

IE supports the HTML5 File API

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

Internet Explorer's support for the HTML5 File API varies by version. IE9 does not support the File API, but IE10 and later versions provide full support for file operations. File API Browser Support The File API allows web applications to read file contents and metadata. Here's the IE support timeline: IE9: No File API support IE10+: Full File API support including FileReader, File, and Blob objects Modern browsers: Complete support across Chrome, Firefox, Safari, and Edge Example: File Reading with File API This example ...

Read More

Change the color of top border with CSS

Ankith Reddy
Ankith Reddy
Updated on 15-Mar-2026 209 Views

The border-top-color CSS property allows you to change the color of an element's top border independently of other borders. This property is useful when you want to create distinctive visual effects or highlight specific elements. Syntax border-top-color: color-value; The color value can be specified using color names, hex codes, RGB values, or HSL values. Example p.demo { border: 3px ...

Read More

Searching an element in Javascript Array

Sharon Christine
Sharon Christine
Updated on 15-Mar-2026 628 Views

JavaScript provides several methods to search for elements in arrays. Each method has its own use case depending on whether you're searching for primitive values or complex objects. Using indexOf() for Primitive Values The indexOf() method searches through the array and returns the index of the first matching element, or -1 if not found. let people = ["Harry", "Martha", "John", "Sam"]; console.log(people.indexOf("John")); console.log(people.indexOf("Jim")); 2 -1 Using find() for Complex Objects The find() method returns the first element that matches the condition provided in the callback function. let people ...

Read More

What is the difference between Math.ceil() and Math.round() methods in JavaScript?

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

Math.ceil() and Math.round() are JavaScript methods that round numbers to integers, but they work differently. Math.ceil() always rounds up to the nearest integer, while Math.round() rounds to the nearest integer using standard rounding rules (0.5 and above rounds up, below 0.5 rounds down). Math.ceil() - Always Rounds Up The Math.ceil() method rounds a number up to the nearest integer, regardless of the decimal value. It always moves toward the greater value. Syntax Math.ceil(x) Example ...

Read More

First element and last element in a JavaScript array?

vineeth.mariserla
vineeth.mariserla
Updated on 15-Mar-2026 839 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
Showing 17341–17350 of 61,297 articles
Advertisements