Array Initilization In JavaScript(One Mimensional)


<body>
<script>

var fruits = [12, 12, 12, 12];

var n=fruits.length;

var i;
var c="";
text="";
text = "<ol type=A>";
for (i = 0; i << n; i++) {
  text += "<li>" + fruits[i] + "</li>";
}
text+= "</ol>";
document.write(text);
</script>
</body>

Array Declaration In JavaScript(One Mimensional)


<body>
<script>

var fruits = [];

var n=parseInt(prompt("how many Subjects"));

var i;
var c=0;
for (i=0;i<n;i++)
{
	fruits[i]=parseInt(prompt("Enter subject "+(i+1)+" marks"))
	c=c+fruits[i];
}
alert(c);
</script>
</body>

Array Assignment In JavaScript(One Mimensional)


<body>
<script>

var fruits = [];

fruits[0]=12;
fruits[1]=12;
fruits[2]=12;
var n=fruits.length;

var i;
var c=0;
for (i=0;i<n;i++)
{
	
	c=c+fruits[i];
}
alert(c);
</script>
</body>

							
							

Array Initilization In JavaScript(Multi Mimensional)


<body>
<script>

var marks = [[1,1,1,1,1],[2,2,2,2,2],[3,3,3,3,3]];


var i;
var c;
for (i=0;i<3;i++)
{	c=0;
	for(j=0;j<5;j++)
	{
		c=c+marks[i][j];
	}
	document.write("Student "+(i+1)+" Marks are"+c+"<br>");
	
	
	
}
</script>
</body>

Array Declaration In JavaScript(Multi Mimensional)


<body>
<script>

var marks = [[],[],[]];


var i;
var c;
var x="";
for (i=0;i<3;i++)
{	c=0;
	for(j=0;j<5;j++)
	{
		marks[i][j]=parseInt(prompt("Enter Student"+(i+1)+" subject "+(j+1)+" marks"))
		c=c+marks[i][j];
	}
	x=x+("Student "+(i+1)+" Marks are"+c+"<br>");
	
	
	
}
document.write(x);
</script>
</body>

Array Assignment In JavaScript(Multi Mimensional)


<body>
<script>

var marks = [[],[],[]];

marks[0][0]=1;
marks[0][1]=1;
marks[0][2]=1;

marks[0][3]=1;

marks[0][4]=1;

marks[1][0]=1;

marks[1][1]=155;

marks[1][2]=1;

marks[1][3]=1;

marks[1][4]=1;

marks[2][0]=1;

marks[2][1]=1;

marks[2][2]=1;

marks[2][3]=11;

marks[2][4]=2;



var i;
var c;
var x="";
for (i=0;i<3;i++)
{	c=0;
	for(j=0;j<5;j++)
	{
		c=c+marks[i][j];
	}
	
	
		x=x+("Student "+(i+1)+" Marks are"+c+"%ltbr>");

}
document.write(x);
</script>
</body>