why is the following code showing undefined? Are we not allowed to create an array with a single value? Putting two values won’t show this error. Is this a problem with Javascript?
<script>
var tech = new Array(21);
alert(tech[0]);
</script>
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
new Array(21)creates an array with a length of 21. If you want to create a single-value array, consisting of a number, use square brackets,[21]:If you want to dynamically fill an array, use the
.pushmethod:When the Array constructor receives one parameter
p, which is a positive number, an array will be created, consisting of p elements. This feature is can be used to repeat strings, for example: