All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

Declare Empty Array In JavaScript

Last Updated : Mar 11, 2024

Declare Empty Array In JavaScript

In this tutorial we will show you the solution of declare empty array in JavaScript, in last session, we understand that how to apply filter on values under arrays having multiple values.

We hope that you understand that article properly. Now, let us understand our today’s article in which we will show you how to declare an empty array.

Step By Step Guide On Declare Empty Array In JavaScript :-

As, there are many ways with the help of which you will understand how to declare an empty array.

Declaration of empty array is just to avoid pointless and incorrect calculation. We can also use length property to empty an array.

But in this article we will understand how to declare an empty array. Now, here below code is given to declare empty arrays in JavaScript.

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>home page</title>
</head>
<body>
<script>
 // for wider scope
 var arrayName=[];
 // for local scope
 let arrayName=[];
 //other ways are
 const array=[];
 //or
 const myarray = new array[];
</script>
</body>
</html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  4. Here, then we create a body tag. All the content which we want to show on browser’s screen or display is always written inside this codes.
  5. One thing to say here that there are many ways with the help of which we are able to create or declare an empty array.
  6. Here, inside body first we create script tag which is a paired tag and after that or say inside script tag, we create many types of arrays.
  7. Here, types mean that we declare arrays in many ways. For wider scope that syntax is different and for local scope the syntax is again different.
  8. Hence, we declare arrays in many forms. In next session, we will show you how to check arrays and it’s done with help of length. It means that we use length attribute to check the length of arrays.
  9. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

At last in conclusion, here we can say that with the help of this article we are able to learn about declaration of an empty array using JavaScript.

I hope this tutorial on declare empty array in JavaScript helps you and the steps and method mentioned above are easy to follow and implement and In next article, we will check our empty array is actual empty or not.