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
Working with Inline CSS
Inline CSS allows you to apply styles directly to HTML elements using the style attribute. This method applies styles to individual elements only, making it useful for quick styling or element-specific customizations. Syntax You can use the style attribute on any HTML element to define inline style rules: Style Attribute Attribute Value ...
Read MoreWhat is the use of _.size() method in JavaScript?
The _.size() method is part of the Underscore.js library and returns the number of elements in arrays, objects, and strings. It provides a consistent way to get the size of various data types. Syntax _.size(collection) Parameters collection: The array, object, or string to count elements from. Return Value Returns a number representing the count of elements in the collection. Example 1: Array Size Find the size of a numeric array using _.size(): var arr = [100, 62, 73, 534, 565]; document.write("Array size: ...
Read MoreWhat is the importance of '+' operator in type conversion in JavaScript?
JavaScript is a dynamically typed language where operations often automatically convert values to the appropriate type. The + operator plays a crucial role in type conversion, behaving differently depending on the operand types. JavaScript provides many ways to convert data from one form to another, with two most common types of conversion: Converting values to strings Converting values to numbers The '+' Operator's Dual Behavior The + operator in JavaScript serves two purposes: Addition: When both operands are numbers String ...
Read MoreJavaScript function to take a number n and generate an array with first n prime numbers
We are required to write a JavaScript function that takes in a number n and returns an array that contains first n prime numbers. We know that prime numbers are those numbers that are only divisible by 1 and themselves like 2, 3, 19, 37, 73 etc. Let's understand the problem with an example − Input: n = 6; Output: prime_numbers = [ 2, 3, 5, 7, 11, 13 ] Using Iteration We will first write a function that checks whether a given number is prime or not and then run a loop ...
Read MoreFormatting text to add new lines in JavaScript and form like a table?
To format text with new lines in JavaScript and create table-like output, use the map() method combined with join(''). The '' character creates line breaks in console output. Syntax array.map(element => `formatted string`).join('') Example: Creating a Table-like Format let studentDetails = [ [101, 'John', 'JavaScript'], [102, 'Bob', 'MySQL'], [103, 'Alice', 'Python'] ]; // Create header let tableHeader = '||Id||Name||Subject||'; // Format data rows let tableRows = studentDetails.map(student => `|${student.join('|')}|` ).join(''); // Combine header ...
Read MoreDividing an array – JavaScript
Let's say, we are required to write a function that takes in an array arr of string / number literals as the first argument and a number n as second argument. We are required to return an array of n subarrays, each of which contains at most arr.length / n elements. And the distribution of elements should be like this − The first element goes in the first subarray, second in second, third in third and so on. Once we have one element in each subarray, we again start ...
Read MoreHow to convert seconds to HH-MM-SS with JavaScript?
In this tutorial, we will learn to convert seconds to Hours, Minutes, and Seconds (HH:MM:SS) format in JavaScript. Converting seconds to a readable time format is essential for displaying durations, timers, or elapsed time in web applications. JavaScript provides several approaches to achieve this conversion. Using the toISOString() Method The toISOString() method is one of the simplest approaches to convert seconds into the standard HH:MM:SS format. This method creates a Date object and extracts the time portion. Syntax var calculatedTime = new Date(null); calculatedTime.setSeconds(seconds); var newTime = calculatedTime.toISOString().substr(11, 8); Example The ...
Read MoreHow to save DIV as Image with HTM5 canvas to image with the extension?
Converting HTML DIV content to images is useful for generating reports, creating downloadable content, or saving visual elements. The html2canvas library makes this process straightforward by converting DOM elements into canvas, which can then be saved as images. Installation First, include the html2canvas library in your HTML: Basic HTML Structure Create a DIV with content you want to convert: Welcome to TutorialsPoint! ...
Read MoreExample of embedded CSS
Embedded CSS allows you to place CSS rules directly within an HTML document using the element. This tag is placed inside the section, and the rules defined will apply to all elements in the document. Syntax /* CSS rules go here */ selector { property: value; } ...
Read MoreHow to count a number of words in given string in JavaScript?
Counting words in a JavaScript string requires handling various whitespace scenarios like multiple spaces, leading/trailing spaces, and newlines. Using regular expressions provides an effective solution. The Challenge Strings can contain irregular spacing that affects word counting: Leading and trailing spaces Multiple consecutive spaces between words Newlines with spaces Empty strings Step-by-Step Approach Step 1: Remove Leading and Trailing Spaces Use regex to eliminate spaces at the start and end of the string: str.replace(/(^\s*)|(\s*$)/gi, ""); Step 2: Reduce Multiple Spaces to Single Space Replace consecutive spaces with a ...
Read More