728x90
SMALL
#javascript
#JavaScript / array (Array) / declare
How to declare an array
Method1
Create an array named jbAry.
var jbAry = new Array();
assign a value.
jbAry[0] = 'Lorem';
jbAry[1] = 'Ipsum';
jbAry[2] = 'Dolor';
Method2
var jbAry = [ 'Lorem', 'Ipsum', 'Dolor' ];
Method3
var jbAry = new Array( 'Lorem', 'Ipsum', 'Dolor' );
example
This is an example of assigning values to an array and then outputting them in order.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>JavaScript</title>
<script>
var jbAry = new Array();
jbAry[0] = 'Lorem';
jbAry[1] = 'Ipsum';
jbAry[2] = 'Dolor';
</script>
</head>
<body>
<script>
for ( var i = 0; i < 3; i++ ) {
document.write( '<p>' + jbAry[i] + '</p>' );
}
</script>
</body>
</html>
728x90
LIST