Call Us : +91-8376986802 (Viber, WhatsApp)

How tp create Arrays using JavaScript ?



var days = new Array();
days[0] = “Sunday”
days[1] = “Monday”
days[2] = “Tuesday”
days[3] = “Wednesday”
days[4] = “Thursday”
days[5] = “Friday”
days[6] = “Saturday”

document.write(“first day is “+days[0])

This produces

first day is Sunday

A more compact way of creating an array is the literal notation:

var days = [“Sunday”,”Monday”,”Tuesday”,”Wednesday”, “Thursday”,”Friday”,”Saturday”];
document.write(“first day is “+days[0])
This produces
first day is Sunday

Leave a Reply