Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » JavaScript

JavaScript | Code to declare an array and assign the elements using array indexing



Here, we are going to learn how to declare an array and how to assign the elements using the array indexing in the JavaScript?
Submitted by Pankaj Singh, on October 10, 2018

Declare an array, assign elements by indexes and print all elements in JavaScript.

Code:

<html>
    <head>
        <script>
            var fruits = [];
            fruits[0]="banana";
            fruits[1]="apple";
            fruits[2]="pineapple";
            fruits[3]="guava";
            fruits[4]="mango";
        </script>
    </head>
    <body>
        <script>
            document.write("<h3>Array : Type 3</h3>")
            document.write("<hr />");
            document.write("<ul>");
            fruits.forEach(function(item){
                document.write("<li>"+item+"</li>");
            });  
            document.write("</ul>");
        </script>
    </body>
</html>

Output

JS | Array Example output






Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.