Articles on Trending Technologies

Technical articles with clear explanations and examples

How to splice duplicate item in array JavaScript

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 730 Views

We have an array of Number / String literals that contain some duplicate values, we have to remove these values from the array without creating a new array or storing the duplicate values anywhere else. We will use the Array.prototype.splice() method to remove entries in-place, and we will take help of Array.prototype.indexOf() and Array.prototype.lastIndexOf() method to determine the duplicacy of any element. The Problem with Forward Iteration When using forEach() to remove duplicates, we encounter index shifting issues. Here's why the basic approach doesn't work perfectly: const arr = [1, 4, 6, 1, 2, 5, ...

Read More

How to find all subsets of a set in JavaScript?

AmitDiwan
AmitDiwan
Updated on 15-Mar-2026 752 Views

To find all subsets of a set in JavaScript, you can use the reduce() method along with map() to generate all possible combinations. A subset is any combination of elements from the original set, including the empty set and the set itself. How It Works The algorithm starts with an empty subset [[]] and for each element in the original array, it creates new subsets by adding that element to all existing subsets. Example const findAllSubsetsOfGivenSet = originalArrayValue => originalArrayValue.reduce( (givenSet, setValue) ...

Read More

Get only specific values in an array of objects in JavaScript?

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

When working with arrays of objects in JavaScript, you often need to extract specific values based on certain criteria. This can be accomplished using several array methods like filter(), map(), and find(). Let's say we have the following array of student objects: var details = [{ studentName: "John", studentMarks: 92 }, { studentName: "David", studentMarks: 89 }, { studentName: "Mike", studentMarks: 98 }]; Using filter() to Get Objects Meeting Criteria ...

Read More

How to call JavaScript function in an alert box?

Saurabh Jaiswal
Saurabh Jaiswal
Updated on 15-Mar-2026 6K+ Views

To call a JavaScript function in an alert box, you can use the alert() function, a built-in function in JavaScript that displays an alert dialog with a specified message. An alert box is a simple dialog box that displays a message to the user and provides an OK button. It is a built-in function in JavaScript that is often used for debugging or displaying simple notifications to the user. Here's an example of how to use the alert() function in JavaScript: alert("Hello, World!"); ...

Read More

How to show the index of the selected option in a dropdown list with JavaScript?

Abhishek Kumar
Abhishek Kumar
Updated on 15-Mar-2026 12K+ Views

In JavaScript, we use the selectedIndex property to get the index of the selected option in a dropdown list. This property returns a zero-based index value that indicates which option is currently selected. Dropdown lists are an essential part of user interfaces, allowing users to select one or multiple options from a predefined list. Understanding how to retrieve the selected option's index is crucial for form handling and user interaction. Using the selectedIndex Property The selectedIndex property is part of the DOM and contains the index of the currently selected option in a dropdown list. The indexing ...

Read More

How to detect a mobile device with JavaScript?

Prince Varshney
Prince Varshney
Updated on 15-Mar-2026 70K+ Views

In this tutorial, we are going to learn how can we detect a mobile device over which we are working using JavaScript. Approach 1: Using the navigator.userAgent Property To detect a mobile device with JavaScript we are going to use the window navigator object which contains all the information regarding a browser. The property which we will use to detect a mobile device will be the userAgent property which is used to return the user-agent header sent to the server by the browser. The value we receive from this property is the browser name, version, and platform i.e., ...

Read More

How can I use Web Workers in HTML5?

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 221 Views

Web Workers allow for long-running scripts that are not interrupted by scripts that respond to clicks or other user interactions and allows long tasks to be executed without yielding to keep the page responsive. Web Workers are background scripts and they are relatively heavyweight and are not intended to be used in large numbers. For example, it would be inappropriate to launch one worker for each pixel of a four-megapixel image. Web Workers are initialized with the URL of a JavaScript file, which contains the code the worker will execute. This code sets event listeners and communicates with ...

Read More

Set the color of the border with CSS

karthikeya Boyini
karthikeya Boyini
Updated on 15-Mar-2026 172 Views

The border-color property in CSS specifies the color of an element's border. It works in conjunction with other border properties like border-style and border-width to create complete border styling. Syntax border-color: color-value; The color value can be specified using: Hex codes: #800000 RGB values: rgb(128, 0, 0) Color names: red, blue, green HSL values: hsl(0, 100%, 25%) Example: Basic Border Color ...

Read More

How to return the response from an asynchronous call in Javascript?

Arnab Chakraborty
Arnab Chakraborty
Updated on 15-Mar-2026 509 Views

Asynchronous programming is common in JavaScript network programming. In this approach, we can download data or perform time-dependent operations without blocking the current execution flow. This article explores techniques to return responses from asynchronous calls in JavaScript. Before diving into solutions, let's examine a common problem developers face with asynchronous calls: The Problem function aTrivialFunction() { ajaxCall(..., function onSuccess(result) { // How do we return result from this function? }); } console.log('result of aTrivialFunction:', aTrivialFunction()); // undefined This AJAX call represents a ...

Read More

Write the dependencies of backbone.js in javascript?

Ayush Gupta
Ayush Gupta
Updated on 15-Mar-2026 292 Views

Backbone.js is a lightweight JavaScript framework that requires specific dependencies to function properly. Understanding these dependencies is crucial for setting up and working with Backbone.js applications. Hard Dependency The only hard dependency (without which Backbone.js won't work at all) is Underscore.js. Underscore is a JavaScript library that provides a whole mess of useful functional programming helpers without extending any built-in objects. // Including Underscore.js is mandatory Optional Dependencies There are other dependencies required as you proceed to use more advanced features of Backbone.js: jQuery or ...

Read More
Showing 17371–17380 of 61,297 articles
Advertisements