Way2tutorial Snippet Editor
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>JavaScript array element access</title> </head> <body> <pre> <!-- Use pre element for work document.writeln() method --> <script type="text/javascript"> var domain = new Array(); // an empty array, length 0 domain.length // return 0 domain[0] = ".com"; domain[1] = ".net"; domain[2] = ".org"; domain[3] = ".gov"; document.writeln( domain[0] ); // return .com document.writeln( domain[1] ); // return .net document.writeln( domain[1 + 1] ); // return .org document.writeln( domain[domain.length - 1] ); // return .gov </script> </pre> </body> </html>