Found 8894 Articles for Front End Technology

How to calculate GCD of two or more numbers/arrays in JavaScript?

Imran Alam
Updated on 01-Jul-2022 12:25:50

554 Views

The greatest common divisor (GCD) of two or more numbers, also known as the greatest common factor (GCF) or highest common factor (HCF), is the largest positive integer that divides a given number without a remainder. In other words, the GCD is the largest number that is a divisor of both numbers.For example, the GCD of 24 and 36 is 12.How to calculate the GCD of two numbers?There are a few different ways to calculate the GCD of two numbers, but the most common method is the Euclidean algorithm.The Euclidean algorithm is an iterative method that starts with two numbers, ... Read More

How to convert a 2D array to a CSV string in JavaScript?

Imran Alam
Updated on 21-Jul-2022 14:34:55

902 Views

The CSV (Comma Separated Values) file format is a popular way of exchanging data between applications and data stores. The CSV file format is simple and easy to understand, and many applications and programming languages support it.In JavaScript, there are a number of ways to convert an array of data into a CSV string. In this tutorial, we'll look at two popular methods: the Array.join() method and the JSON.stringify() method.Using the Array.join() MethodThe Array.join() method is a built-in method of the JavaScript Array object. It can be used to join the elements of an array into a single string. The ... Read More

How to convert a string into an integer without using parseInt() function in JavaScript?

Imran Alam
Updated on 01-Jul-2022 12:06:56

2K+ Views

The parseInt() is a built-in function in JavaScript that parses a string and returns an integer. However, there are times when we want to convert a string into an integer without using this function. In this article, we'll explore how to do just that.Using the unary plus operatorOne way to convert a string into an integer is by using the unary plus operator. This operator converts its operand into a number. For instance, the following program converts the string "123" into the number 123 −Example 1    Examples                   ... Read More

How to return true if the parent element contains the child element in JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:51:52

6K+ Views

In this tutorial, we are going to look at how we can return true if the parent element contains the child element in JavaScript. Assuming you have two HTML elements, a parent element, and a child element, and you want to know if the parent element contains the child element.Using the Node.contains() methodThe Node interface's contains() method returns a Boolean value, indicating whether a node is a descendant of a given node or not.If you want to know if the parent element contains the child element, you can use the Node.contains() method.Here's a simple example −    Some text The ... Read More

What is difference between Microtask Queue and Callback Queue in asynchronous JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:41:46

3K+ Views

In asynchronous JavaScript, there are two ways to schedule tasks – microtask queue and callback queue. Both queues are handled differently by the JavaScript engine.Microtask QueueA Microtask queue is a queue of tasks that are executed after the current task. The microtask queue is handled by the JavaScript engine before it moves on to the next task in the callback queue.ExampleHere’s an example of how microtask queue works −    Examples               console.log('start');         setTimeout(function() {          console.log('setTimeout');       }, 0);   ... Read More

How to remove elements from an array until the passed function returns true in JavaScript?

Imran Alam
Updated on 01-Jul-2022 08:33:48

369 Views

In JavaScript, there are various ways to remove elements from an array until the passed function returns true. In this tutorial, we are going to look at 3 methods in detail.Using Array.prototype.filter()The Array.prototype.filter() method can be used to remove elements from an array until the passed function returns true. Please refer to the Array filter() method for more details.Example 1The following code shows how to use this method −    Examples                   var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];       function ... Read More

How to check if a value is object-like in JavaScript?

Imran Alam
Updated on 24-Jun-2022 08:24:55

89 Views

In JavaScript, an object-like value is a value that is not a primitive value and is not undefined. An object-like value is any value that is not a primitive value, including functions, arrays, and objects. There are different methods for checking if a value is objectlike in JavaScript. In this article, we are going to look at 3 methods for checking if a value is object-like in JavaScript.Using the typeof OperatorThe typeof operator is a built-in operator in JavaScript that is used to check the type of a value. The typeof operator returns a string that is the type of ... Read More

How to Create a Currency Converter in JavaScript?

Imran Alam
Updated on 24-Jun-2022 08:33:21

8K+ Views

In this tutorial, we will be discussing how to create a currency converter in JavaScript. We will be discussing the various steps involved in creating such a converter.What is a currency converter?A currency converter is a tool that helps you convert one currency to another. For example, if you are from the United States and you are traveling to Europe, you will need to use a currency converter to convert your US dollars into Euros.Why use JavaScript to create a currency converter?JavaScript is a versatile programming language that can be used to create a wide variety of applications, including web-based ... Read More

How to create a moving div using JavaScript?

Imran Alam
Updated on 24-Jun-2022 07:50:52

11K+ Views

A moving div is a web page element that can be caused to move across the screen, or change position on the screen, automatically. The position is changed by adjusting the left and top style properties. Creating a moving div using JavaScript is a relatively simple task. All that is required is a little bit of HTML, CSS, and JavaScript code. In this tutorial, we will go over how to create a moving div using JavaScript.HTML CodeThe first thing we need is some HTML code. We will create a div with an id of "movingDiv". Inside of this div, we ... Read More

JavaScript: How to remove the key-value pairs corresponding to the given keys from an object?

Imran Alam
Updated on 24-Jun-2022 07:40:03

11K+ Views

In JavaScript, objects can be created to store data as key-value pairs. The data in an object can be accessed using the dot notation (obj.key) or the bracket notation (obj["key"]). See the below example −let obj = { key1: "value1", key2: "value2", key3: "value" };We can remove the key-value pairs corresponding to the given keys from an object but in this tutorial, we are going to look at 3 methods.Using the delete operatorThe delete operator is used to delete a property of an object. The delete operator will not delete the variable itself, but only the value of the variable.ExampleSee ... Read More

Advertisements