Found 6710 Articles for Javascript

How to create an array of integers in JavaScript?

Alshifa Hasnain
Updated on 18-Mar-2025 11:14:51

18K+ Views

In this article, we will learn to create an array of integers in JavaScript. The Array parameter is a list of strings or integers. When you specify a single numeric parameter with the Array constructor, you specify the initial length of the array. The maximum length allowed for an array is 4, 294, 967, 295. Different Approaches The following are the two different approaches to creating an array of integers in JavaScript − Using Array Literals Using the Array Constructor Using Array Literals One of the simplest ways to create ... Read More

How to create arrays in JavaScript?

Anjana
Updated on 15-Jun-2020 07:32:09

436 Views

To create an array in JavaScript, simply assign values −var animals = ["Dog", "Cat", "Tiger"];You can also use the new keyword to create arrays in JavaScript −var animals = new Array("Dog", "Cat", "Tiger");The Array parameter is a list of strings or integers. When you specify a single numeric parameter with the Array constructor, you specify the initial length of the array. The maximum length allowed for an array is 4, 294, 967, 295.ExampleLet’s see an example to create arrays in JavaScriptLive Demo           JavaScript Arrays                   ... Read More

What is the best way to concatenate strings in JavaScript?

Akshaya Akki
Updated on 13-Jan-2020 08:25:31

940 Views

The best and fastest way to concatenate strings in JavaScript is to use the + operator. You can also use the concat() method.ExampleYou can try to run the following code to concatenate strings in JavaScriptLive Demo           JavaScript Concatenation                        var str1 = "Hello";          var str2 = "World";          var res = str1 + str2;          document.write(res);          

How do I replace a character at a particular index in JavaScript?

Shubham Vora
Updated on 20-Jul-2022 08:56:37

2K+ Views

It is often required to update the string and replace the single character at a particular index while programming with JavaScript. JavaScript doesn’t contain the built-in method to replace the single character at the particular index in the string as the Java and C++, but we can use some other built-in methods and create custom logic to solve our problem.In this tutorial, we have two methods to replace the character at a particular index in the string and update the string. One is by converting string to array, and another is using the substr() built-in method of JavaScript.Replace Character by ... Read More

How to generate Prime Numbers in JavaScript?

Ayyan
Updated on 13-Jan-2020 08:19:16

3K+ Views

To generate prime numbers in JavaScript, you can try to run the following codeExampleLive Demo           JavaScript Prime                        for (var limit = 1; limit

How to get the length of a string in JavaScript?

Shubham Vora
Updated on 14-Sep-2022 08:32:15

3K+ Views

In this tutorial, we will learn how to get the length of the string in JavaScript. While writing any string in JavaScript, we might need to know the number of characters present in it. By knowing an easy method to calculate the length of a string in JavaScript, we can increase or decrease the words and phrases. There are different ways to get the length of a string, but the easiest way is to use the length property of the string. Let’s discuss the different approaches in detail. Using the string.length Property If you want to use a method ... Read More

Is there a Boolean Typed Array in JavaScript?

Shubham Vora
Updated on 15-Nov-2022 09:19:41

397 Views

In this tutorial, we will learn if there is a Boolean Typed Array in JavaScript. Typed Arrays are the objects same as arrays by using we can read or write raw binary data. It is useful to carry advanced information that contains lots of data like audio or videos fast and without distortion compared to our traditional way. The machine can only understand 0s and 1s. The typed arrays saved the information in an array of binary data. So, it becomes easier to transport the data from one end to another. Now come to the question- Is there a Boolean ... Read More

How do I compare String and Boolean in JavaScript?

Shubham Vora
Updated on 20-Jul-2022 08:08:25

4K+ Views

In this tutorial, we will learn to compare a string to the Boolean in JavaScript. The JavaScript has an equality operator to compare one value with another value.There are two types of equality operators in JavaScript; one is an equality operator (==), and another is a strict equality operator (===). The difference between both of them is they compare operands differently.The equality operator compares the only values of both operands and returns the Boolean value.The strict equality operators first compare the values of both operands, and if the values match, it compares the data type of both operands. In such ... Read More

What is an exclamation “!” operator in JavaScript?

Alankritha Ammu
Updated on 15-Jun-2020 07:12:10

2K+ Views

The exclamation operator is to perform negation on an expression.ExampleYou can try to run the following code to learn how to implement exclamation(!) operator in JavaScript −Live Demo           JavaScript Boolean                        var answer = true;          document.write(answer);          document.write(""+!answer);          

How to convert a Boolean to Integer in JavaScript?

Ayyan
Updated on 15-Jun-2020 07:11:35

412 Views

Yes, it is possible to convert Boolean to Integer in JavaScript, using the Ternary Operator.ExampleYou can try to run the following code to convert Boolean to Integer −Live Demo           JavaScript Boolean                        var answer = true;          document.write(answer);          var pass_marks = answer ? 90 : 40;          document.write("Passing Marks: "+pass_marks);          

Advertisements