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
Javascript Articles
Page 389 of 534
Getting equal or greater than number from the list of numbers in JavaScript
We are required to write a JavaScript function that takes in an array of numbers as the first argument and a single number as the second argument. The function should return an array of all the elements from the input array that are greater than or equal to the number taken as the second argument. Example Following is the code − const arr = [56, 34, 2, 7, 76, 4, 45, 3, 3, 34, 23, 2, 56, 5]; const threshold = 40; const findGreater = (arr, num) => { const res = ...
Read MoreUsage of color property in CSS
The color property in CSS is used to set the color of text content. It accepts various color formats including color names, hexadecimal values, RGB, and HSL values. Syntax color: value; Color Value Formats The color property accepts several formats: Color names: red, blue, green, etc. Hexadecimal: #ff0000, #00ff00, #0000ff RGB: rgb(255, 0, 0) RGBA: rgba(255, 0, 0, 0.5) with transparency HSL: hsl(0, 100%, 50%) Example: Using Color Names ...
Read MoreSum of all prime numbers in an array - JavaScript
We are required to write a JavaScript function that takes in an array of numbers and returns the sum of all the prime numbers present in the array. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. For example, 2, 3, 5, 7, 11 are prime numbers. Let's say the following is our array: const arr = [43, 6, 6, 5, 54, 81, 71, 56, 8, 877, 4, 4]; The function should sum the prime numbers: 43 + 5 + 71 ...
Read MoreHow to set the cases for a text in CSS?
The text-transform property in CSS allows you to control the capitalization of text without modifying the original HTML content. This property is particularly useful for styling headings, navigation links, and other text elements consistently across your website. Syntax text-transform: none | capitalize | uppercase | lowercase | initial | inherit; Property Values The text-transform property accepts the following values: none - No transformation (default value) capitalize - First letter of each word is capitalized uppercase - All letters are converted ...
Read MoreFinding reversed index of elements in arrays - JavaScript
We need to create a JavaScript function that finds the reversed index of an element in an array without actually reversing it. This function calculates what position an element would occupy if the array were reversed. If the element is not present in the array, the function returns -1. Otherwise, it returns the index position the element would have in a reversed array. Understanding Reversed Index The reversed index is calculated using the formula: length - originalIndex - 1 For example, in array [45, 74, 34, 32, 23, 65]: Element 23 is at index 4 ...
Read MoreHow to set the whitespace between text in CSS?
The CSS white-space property controls how whitespace characters (spaces, tabs, line breaks) are handled within text elements. This property is essential for controlling text formatting and layout. Syntax white-space: value; White-space Property Values Value Spaces/Tabs Line Breaks Text Wrapping normal Collapsed Ignored Yes pre Preserved Preserved No nowrap Collapsed Ignored No pre-wrap Preserved Preserved Yes pre-line Collapsed Preserved Yes Example: Using white-space: pre The pre value preserves all whitespace and line breaks, similar to the HTML tag: ...
Read MoreCheck whether a string ends with some other string - JavaScript
In JavaScript, there are multiple ways to check if a string ends with another string. The most straightforward approach is using the built-in endsWith() method, though you can also implement custom solutions. Using String.endsWith() (Recommended) The endsWith() method is the standard way to check if a string ends with a specific substring: const str1 = 'this is just an example'; const str2 = 'ample'; console.log(str1.endsWith(str2)); // true console.log(str1.endsWith('temple')); // false console.log(str1.endsWith('example')); // true true false true Custom Implementation ...
Read MoreHow to style images with CSS?
CSS provides numerous properties to style and enhance images on web pages. You can control dimensions, transparency, borders, filters, and positioning to create visually appealing designs. Basic Image Styling Properties Common CSS properties for styling images include: width/height: Control image dimensions opacity: Set transparency (0 to 1) border: Add borders around images border-radius: Create rounded corners filter: Apply visual effects Setting Image Opacity The opacity property controls image transparency, with values from 0 (fully transparent) to 1 (fully opaque): ...
Read MoreDeleting the duplicate strings based on the ending characters - JavaScript
We are required to write a JavaScript function that takes in an array of strings and deletes each one of the two strings that ends with the same character. For example, if the actual array is: const arr = ['Radar', 'Cat', 'Dog', 'Car', 'Hat']; Then we have to delete duplicates and keep only one string ending with the same character. In this case, 'Cat', 'Car', and 'Hat' all end with 't', 'r', and 't' respectively, so we need to remove duplicates based on the last character. How It Works The algorithm uses a ...
Read MoreUsage of width property with CSS
The width property in CSS is used to set the width of elements, including images. This property accepts values in various units such as pixels (px), percentages (%), em, rem, and other CSS length units. When using percentage values, the width is calculated relative to the containing element's width. Syntax width: value; Common Values Pixels (px): Absolute unit - width: 200px; Percentage (%): Relative to parent container - width: 50%; Auto: Browser calculates width automatically - width: auto; Em/Rem: Relative to font size - width: 10em; Example: Setting Image Width ...
Read More