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
Explain JavaScript text alert
The JavaScript alert() function is used to display a popup message to the user. It's a built-in browser method that creates a modal dialog box with a message and an "OK" button. Syntax alert(message); Parameters The alert() function accepts one parameter: message - A string that specifies the text to display in the alert box Basic Example JavaScript Alert Example JavaScript Text ...
Read MoreHow to remove an object using filter() in JavaScript?
The filter() method creates a new array with elements that pass a test condition. It's commonly used to remove objects from arrays based on specific criteria. Initial Array Let's start with an array of objects where some have a details property and others don't: let objectValue = [ { "id": "101", "details": { "Name": "John", "subjectName": "JavaScript" }}, { "id": "102", "details": { "Name": "David", "subjectName": "MongoDB" }}, { "id": "103" } ]; console.log("Original array:"); console.log(objectValue); Original array: [ ...
Read MoreHow to move all capital letters to the beginning of the string in JavaScript?
To move all capital letters to the beginning of a string in JavaScript, we can use the sort() method with a regular expression to identify uppercase letters and rearrange them. Let's say we have the following string: my name is JOHN SMITH We'll use sort() along with the regular expression /[A-Z]/ to move all capital letters to the beginning of the string. Example var moveAllCapitalLettersAtTheBeginning = [...'my name is JOHN SMITH'] .sort((value1, value2) => /[A-Z]/.test(value1) ? /[A-Z]/.test(value2) ? 0 : -1 : 0).join(''); console.log("After moving all capital letters at the beginning:"); console.log(moveAllCapitalLettersAtTheBeginning); ...
Read MoreImplementing Priority Sort in JavaScript
We are required to write a JavaScript function that takes in two arrays of numbers, second being smaller in size than the first. Our function should return a sorted version of the first array (in increasing order) but put all the elements that are common in both arrays to the front. For example − If the two arrays are − const arr1 = [5, 4, 3, 2, 1]; const arr2 = [2, 3]; Then the output should be − [2, 3, 1, 4, 5] How It Works The priority ...
Read MoreAre array of numbers equal - JavaScript
We need to write a JavaScript function that takes in two arrays of numbers and checks for their equality based on specific criteria. The arrays will be considered equal if: They contain the same elements and in the same order. The product of all the elements of the first array and second array is equal. Example Arrays The first array of numbers: const first = [3, 5, 6, 7, 7]; The second array of numbers: const second = [7, 5, 3, 7, 6]; ...
Read MoreHow to call a JavaScript function on a click event?
To call a function on click event in JavaScript, you can use either the addEventListener method or the onclick event attribute. The addEventListener method is a general way to attach an event handler to a DOM element, and it allows you to specify the event and the callback function to be called when the event occurs. The onclick attribute is a specific event attribute that allows you to specify a JavaScript function to be called when the element is clicked. Both methods allow you to specify a function to be called when the element is clicked, but the addEventListener ...
Read MoreHow to add 30 minutes to a JavaScript Date object?
In JavaScript, there are multiple ways to add 30 minutes to a Date object. This tutorial covers two effective methods: using the setMinutes() method and using the getTime() method. Using the setMinutes() Method The setMinutes() method sets the minutes for a date object and automatically handles overflow to the next hour or day. Syntax Date.setMinutes(min, sec, ms); Parameters min − An integer between 0 and 59, representing the minutes. sec − An integer between 0 and 59, representing the seconds. Optional. ms ...
Read MoreHow to use comments to prevent JavaScript Execution?
Comments in JavaScript are essential for temporarily disabling code execution during development and testing. Instead of deleting code, you can comment it out to preserve it while testing alternatives. JavaScript supports multiple comment styles, each serving different purposes for code management and documentation. Comment Types and Rules Any text between // and the end of a line is treated as a comment and ignored by JavaScript. Any text between /* and */ is treated as a comment and may span multiple lines. JavaScript recognizes the HTML comment opening sequence is not recognized by JavaScript, so ...
Read MoreHow to return the position of the element relative to floating objects in JavaScript?
This tutorial teaches us how to return the position of the element relative to floating objects in JavaScript. To set the relative position or to get or return the relative position we are going to use the 'clear' property of JavaScript which is defined under the style property of an object. The CSS clear property controls how an element behaves next to floating elements. It can have values like 'left', 'right', 'both', or 'none'. When an element has the clear property set, it will move down to avoid overlapping with floated elements on the specified side. Syntax ...
Read MoreHow to set the minimum width of an element with JavaScript?
Use the minWidth property in JavaScript to set the minimum width of an element. This property ensures an element maintains at least the specified width, even when its content or CSS would make it smaller. Syntax element.style.minWidth = "value"; The value can be specified in pixels (px), percentages (%), or other CSS units like em, rem, or vw. Example: Setting Minimum Width #box { width: 50%; ...
Read More