Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
How to convert a value to a number in JavaScript?
JavaScript provides several methods to convert values to numbers. Each method handles different types of input and has specific use cases. Let's explore the four main approaches: Number(), parseInt(), parseFloat(), and the unary operator (+). Using Number() Method The Number() method converts any value to a number. It's the most comprehensive conversion method and handles various data types. Convert value to number using Number() Number() Method Examples ...
Read MoreConvert HH:MM:SS to seconds with JavaScript?
To convert HH:MM:SS to seconds with JavaScript, we use simple arithmetic operations like multiplication and addition. We split the time string and convert each component to seconds using the formula: hours × 3600 + minutes × 60 + seconds. In this article, we are given a time in HH:MM:SS format and our task is to convert it to total seconds using JavaScript. Steps to Convert HH:MM:SS to Seconds Use the split() function to separate hours, minutes, and seconds by colon delimiter. Convert hours to seconds by multiplying by 3600 ...
Read MoreFinding shared element between two strings - JavaScript
We are required to write a JavaScript function that takes in two strings that may / may not contain some common elements. The function should return an empty string if no common element exists otherwise a string containing all common elements between two strings. Following are our two strings − const str1 = 'Hey There!!, how are you'; const str2 = 'Can this be a special string'; Example Following is the code − const str1 = 'Hey There!!, how are you'; const str2 = 'Can this be a special string'; const ...
Read MoreReturn 5 random numbers in range, first number cannot be zero - JavaScript
We are required to write a JavaScript function that generates an array of exactly five unique random numbers. The condition is that all the numbers have to be in the range [0, 9] and the first number cannot be 0. Example Following is the code − const fiveRandoms = () => { const arr = [] while (arr.length < 5) { const random = Math.floor(Math.random() * 10); if (arr.indexOf(random) > -1){ ...
Read MoreHow to get the number of seconds between two Dates in JavaScript?
In JavaScript, calculating the difference between two dates in seconds is a common requirement for timers, age calculators, and duration displays. JavaScript Date objects provide millisecond precision, which we can easily convert to seconds. Using the getTime() Method The getTime() method returns the number of milliseconds since January 1, 1970 UTC. By subtracting two timestamps and dividing by 1000, we get the difference in seconds. Syntax let date1 = new Date("Aug 12, 2022 19:45:25"); let date2 = new Date("Aug 14, 2022 19:45:25"); let seconds = Math.abs(date1.getTime() - date2.getTime()) / 1000; Example ...
Read MoreHow to set the style of the top border with JavaScript?
In this tutorial, we shall learn to set the style of the top border with JavaScript. To set the style of the top border in JavaScript, use the borderTopStyle property. This property allows you to dynamically change the visual appearance of an element's top border. Let us discuss the property available in JavaScript to achieve this in brief. Using the borderTopStyle Property With the Style borderTopStyle property, we can set or return the style of the top border of an element. Syntax Following is the syntax to set the style of the top border using ...
Read MorePlay local (hard-drive) video file with HTML5 video tag?
The HTML5 tag allows you to play local video files from the user's hard drive using JavaScript's File API and URL.createObjectURL() method. This technique works with MP4, WebM, and Ogg video formats. HTML Structure Create a file input and video element: Local Video Player Your browser does not support the video tag. ...
Read MoreTopological sorting using Javascript DFS
A topological sort or topological ordering of a directed graph is a linear ordering of its vertices such that for every directed edge UV from vertex u to vertex v, u comes before v in the ordering. This only makes sense in directed acyclic graphs (DAGs). There are many places where topological sort makes a lot of sense. For example, let's say you're following a recipe, in this, there are some steps that are prerequisites for going to the next steps. Similarly, during college when selecting courses, there are prerequisites for more advanced courses which themselves may be prerequisites ...
Read MoreHow to freeze an Object in JavaScript?
In JavaScript, Object.freeze() makes an object immutable by preventing modifications to its properties. Once frozen, you cannot add, delete, or modify properties of the object. Syntax Object.freeze(obj) Parameters obj: The object to freeze. Returns the same object that was passed to the function. How Object.freeze() Works When an object is frozen: New properties cannot be added Existing properties cannot be removed Existing property values cannot be changed The object's prototype cannot be changed Example: Basic Object Freezing // Create an object with properties ...
Read MoreHow to convert Array to Set in JavaScript?
This tutorial will teach you how to eliminate duplicate values from an array by converting it to a Set in JavaScript. Sets are collections that store only unique values. When you need to remove duplicates from an array or leverage the unique properties of Sets, converting an array to a Set is the most efficient approach. Using the Set Constructor (Recommended) The Set constructor accepts any iterable object, including arrays, and automatically removes duplicate values. Convert Array to Set - Using Set Constructor ...
Read More