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
TypedArray.byteLength property in JavaScript
The byteLength property of the TypedArray object represents the length of the TypedArray in bytes. It is a read-only property that returns the size of the underlying buffer used by the typed array. Syntax typedArray.byteLength Example: Basic Usage JavaScript Example var buffer = new ArrayBuffer(156); var float32 = new Float32Array(buffer); document.write("ByteLength: " + float32.byteLength); ...
Read MoreHow to calculate total time between a list of entries?
Let's say, we have an array that contains some data about the speed of a motor boat during upstreams and downstreams like this − Following is our sample array − const arr = [{ direction: 'upstream', velocity: 45 }, { direction: 'downstream', velocity: 15 }, { direction: 'downstream', velocity: 50 }, { direction: 'upstream', velocity: 35 }, { direction: 'downstream', velocity: 25 }, { ...
Read MoreJavaScript Adding array name property to JSON object [ES5] and display in Console?
In JavaScript, you can add a JSON object to an array and assign it a property name for better organization. This is useful when you need to convert object data into array format while maintaining structure. Initial Object Setup Let's start with a sample customer object: var customerDetails = { "customerFirstName": "David", "customerLastName": "Miller", "customerAge": 21, "customerCountryName": "US" }; Adding Object to Array Using push() Create a new array and use the push() method to add the ...
Read MoreHow to use JavaScript to set cookies for a specific page only?
We can set cookies for a specific page only using JavaScript. We use the path attribute of the document.cookie property to set the cookie on a specific webpage. Cookies are small text files (4 KB) that store important information such as username, email, session id, and other preferences that help customize the webpage for a particular user. The pathname property of the Window location returns a string containing the path of the current webpage. The path is basic information about where the current webpage is stored on the server. document.cookie Syntax The document.cookie property returns a list ...
Read MoreHow can I round a number to 1 decimal place in JavaScript?
In this tutorial, we will learn to round a number to a one decimal place in JavaScript. There are various needs to round the float numbers and show particular digits after the decimal point. In our case, we need to show only one digit after the decimal point. However, we will create a customizable function that can round off the number and show the particular number of digits after the decimal point at the end of this tutorial. This example lets users understand the fundamental need to round a number to a single decimal digit. Suppose you are ...
Read MoreHow to call a function in JavaScript?
JavaScript allows us to write our own functions as well. To invoke a function somewhere later in the script, you would simply need to write the name of that function. Function Declaration Before calling a function, you need to declare it. Here's the basic syntax: function functionName() { // Code to execute } Calling a Function Once declared, you can call a function by writing its name followed by parentheses: function sayHello() ...
Read MoreWith JavaScript RegExp find a character except newline?
To find a character except for a newline, use the dot metacharacter . (period). The dot matches any single character except the newline character (). Syntax /./ // Matches any character except newline /.+/ // Matches one or more characters except newline /a.b/ // Matches 'a', any character, then 'b' Example JavaScript Regular Expression ...
Read MoreSet the font style with CSS
To set the font style, use the font-style property. This CSS property allows you to make text appear italic, normal, or oblique. Syntax font-style: normal | italic | oblique; Values normal - Default font style (upright text) italic - Slanted version of the font (if available) oblique - Artificially slanted text Example: Italic Font Style You can try to run the following code to set the font-style to italic with CSS: Font Style Example ...
Read MoreTypedArray.byteOffset property in JavaScript
The byteOffset property of TypedArray returns the offset (in bytes) from the start of the ArrayBuffer where the typed array begins. Syntax typedArray.byteOffset Parameters This is a property, not a method, so it takes no parameters. Return Value Returns a number representing the byte offset from the beginning of the ArrayBuffer. Example 1: TypedArray at Buffer Start JavaScript byteOffset Example var buffer = new ArrayBuffer(16); ...
Read MoreHow to write a JavaScript function that returns true if a portion of string 1 can be rearranged to string 2?
We need to write a function that checks if the characters from one string can be rearranged to form another string. This is essentially checking if one string contains all the characters needed to build the second string. The function scramble(str1, str2) should return true if characters from str1 can be rearranged to match str2, otherwise false. Problem Examples str1 = 'cashwool', str2 = 'school' → true (cashwool contains: c, a, s, h, w, o, o, l - enough to make 'school') str1 = 'katas', str2 = 'steak' → false (katas missing 'e' ...
Read More