Javascript Print Array to Console
Learn How to print an array in a javascript console with simple steps.
Step by Step Guide to a print array value
1. To create an array in HTML, we use the “const” keyword. Then we give the identifier name and give the array values inside the square brackets “[ ]”. Then we should give the values of the array inside the double quotes. A comma should be used to separate each array value, see the below code for an example.
const fruits = ["grapes", "Orange", "Apple", "Mango"];
2. To all the array values to the console, we can use the “console.log()” function and give the array name as a value.
console.log(fruits);
Example:
<html>
<head>
<title>HTML to Bootstrap</title>
</head>
<style type="text/css">
button{ position:absolute; right:0; }
</style>
<body>
<script type="text/javascript">
const fruits = ["grapes", "Orange", "Apple", "Mango"];
console.log(fruits);
</script>
</body>
</html>
Output: