SlideShare a Scribd company logo
JavaScript Arrays
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
JavaScript Arrays
 JavaScript arrays are used to store multiple values in a
single variable.
 Declaration of an Array
There are basically two ways to declare an array.
Example:
 var House = [ ]; // method 1
var House = new array(); // method 2
Example
 <html>
 <body>
 <h2>JavaScript Arrays</h2>
 <p id="demo"></p>
 <script>
 var cars = [“Maruti", “Hundai", "BMW"];
 document.getElementById("demo").innerHTML = cars;
 </script>
 </body>
 </html>
 Output: JavaScript Arrays
 Maruti,Hundai,BMW
Creating an Array
 Using an array literal is the easiest way to create a
JavaScript Array.
 Syntax:
 var array_name = [item1, item2, ...];
Using the JavaScript Keyword new
 The following example also creates an Array, and
assigns values to it:
 <script>
 var cars = new Array(“Maruti", “Hundai", "BMW");
 document.getElementById("demo").innerHTML =
cars;
 </script>
Access the Elements of an Array
 <script>
 var cars = [“Maruti", “Hundai", "BMW"];
 document.getElementById("demo").innerHTML =
cars[0];
 </script>
 Output: Maruti
Changing an Array Element
 <script>
 var l = [“xy", “yz", “zx"];
 l[0] = “ab";
 document.getElementById("demo").innerHTML = I;
 Output: ab, yz, zx
Looping Array Elements
 <script>
 var fruits, text, fLen, i;
 fruits = ["Banana", "Orange", "Apple", "Mango"];
 fLen = fruits.length;
 text = "<ul>";
 for (i = 0; i < fLen; i++) {
 text += "<li>" + fruits[i] + "</li>";
 }
 text += "</ul>";
 document.getElementById("demo").innerHTML = text;
 </script>
 Output:
 Banana
 Orange
 Apple
 Mango
Access the Full Array
 <script>
 var shapes = [“circle", “triangle", “square"];
document.getElementById("demo").innerHTML =
cars;
 </script>
Output: circle, triangle, square
Ad

More Related Content

What's hot (20)

Form using html and java script validation
Form using html and java script validationForm using html and java script validation
Form using html and java script validation
Maitree Patel
 
Css backgrounds
Css   backgroundsCss   backgrounds
Css backgrounds
AbhishekMondal42
 
jQuery for beginners
jQuery for beginnersjQuery for beginners
jQuery for beginners
Arulmurugan Rajaraman
 
Html forms
Html formsHtml forms
Html forms
Himanshu Pathak
 
JavaScript - Chapter 11 - Events
 JavaScript - Chapter 11 - Events  JavaScript - Chapter 11 - Events
JavaScript - Chapter 11 - Events
WebStackAcademy
 
Javascript variables and datatypes
Javascript variables and datatypesJavascript variables and datatypes
Javascript variables and datatypes
Varun C M
 
JavaScript - Chapter 8 - Objects
 JavaScript - Chapter 8 - Objects JavaScript - Chapter 8 - Objects
JavaScript - Chapter 8 - Objects
WebStackAcademy
 
MYSQL - PHP Database Connectivity
MYSQL - PHP Database ConnectivityMYSQL - PHP Database Connectivity
MYSQL - PHP Database Connectivity
V.V.Vanniaperumal College for Women
 
VB Script
VB ScriptVB Script
VB Script
Satish Sukumaran
 
Introduction to JavaScript Basics.
Introduction to JavaScript Basics.Introduction to JavaScript Basics.
Introduction to JavaScript Basics.
Hassan Ahmed Baig - Web Developer
 
Data types in php
Data types in phpData types in php
Data types in php
ilakkiya
 
Threads in JAVA
Threads in JAVAThreads in JAVA
Threads in JAVA
Haldia Institute of Technology
 
Javascript validating form
Javascript validating formJavascript validating form
Javascript validating form
Jesus Obenita Jr.
 
PHP FUNCTIONS
PHP FUNCTIONSPHP FUNCTIONS
PHP FUNCTIONS
Zeeshan Ahmed
 
JavaScript Tutorial
JavaScript  TutorialJavaScript  Tutorial
JavaScript Tutorial
Bui Kiet
 
Introducing CSS Grid
Introducing CSS GridIntroducing CSS Grid
Introducing CSS Grid
Jason Yingling
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
Rachel Andrew
 
Form Validation in JavaScript
Form Validation in JavaScriptForm Validation in JavaScript
Form Validation in JavaScript
Ravi Bhadauria
 
Bootstrap grids
Bootstrap gridsBootstrap grids
Bootstrap grids
Webtech Learning
 
Php array
Php arrayPhp array
Php array
Nikul Shah
 

Similar to Java script array (20)

Java Script ppt
Java Script pptJava Script ppt
Java Script ppt
Priya Goyal
 
introduction to java scriptsfor sym.pptx
introduction to java scriptsfor sym.pptxintroduction to java scriptsfor sym.pptx
introduction to java scriptsfor sym.pptx
gayatridwahane
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core Javascript
Arti Parab Academics
 
29. Treffen - Tobias Meier - TypeScript
29. Treffen - Tobias Meier - TypeScript29. Treffen - Tobias Meier - TypeScript
29. Treffen - Tobias Meier - TypeScript
.NET User Group Rhein-Neckar
 
how to use java script classes in java script with example
how to use java script classes in java script with examplehow to use java script classes in java script with example
how to use java script classes in java script with example
MannPerfect
 
PHP-Part3
PHP-Part3PHP-Part3
PHP-Part3
Ahmed Saihood
 
Wt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technologyWt unit 2 ppts client sied technology
Wt unit 2 ppts client sied technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Wt unit 2 ppts client side technology
Wt unit 2 ppts client side technologyWt unit 2 ppts client side technology
Wt unit 2 ppts client side technology
PUNE VIDYARTHI GRIHA'S COLLEGE OF ENGINEERING, NASHIK
 
Object Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayObject Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. Array
AndiNurkholis1
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
JoeDinaso
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
ABCs of Programming_eBook Contents
ABCs of Programming_eBook ContentsABCs of Programming_eBook Contents
ABCs of Programming_eBook Contents
Ashley Menhennett
 
Professional JavaScript Development - Creating Reusable Code
Professional JavaScript Development -  Creating Reusable CodeProfessional JavaScript Development -  Creating Reusable Code
Professional JavaScript Development - Creating Reusable Code
Wildan Maulana
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
Frayosh Wadia
 
Java script arrays
Java script arraysJava script arrays
Java script arrays
Frayosh Wadia
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
Design Patterns in Automation Framework.pdf
Design Patterns in Automation Framework.pdfDesign Patterns in Automation Framework.pdf
Design Patterns in Automation Framework.pdf
ArunVastrad4
 
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptxChapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
KelemAlebachew
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
Salman Memon
 
Lab manual asp.net
Lab manual asp.netLab manual asp.net
Lab manual asp.net
Vivek Kumar Sinha
 
introduction to java scriptsfor sym.pptx
introduction to java scriptsfor sym.pptxintroduction to java scriptsfor sym.pptx
introduction to java scriptsfor sym.pptx
gayatridwahane
 
FYBSC IT Web Programming Unit III Core Javascript
FYBSC IT Web Programming Unit III  Core JavascriptFYBSC IT Web Programming Unit III  Core Javascript
FYBSC IT Web Programming Unit III Core Javascript
Arti Parab Academics
 
how to use java script classes in java script with example
how to use java script classes in java script with examplehow to use java script classes in java script with example
how to use java script classes in java script with example
MannPerfect
 
Object Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. ArrayObject Oriented Programming - 5.1. Array
Object Oriented Programming - 5.1. Array
AndiNurkholis1
 
Power shell examples_v4
Power shell examples_v4Power shell examples_v4
Power shell examples_v4
JoeDinaso
 
FYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III JavascriptFYBSC IT Web Programming Unit III Javascript
FYBSC IT Web Programming Unit III Javascript
Arti Parab Academics
 
ABCs of Programming_eBook Contents
ABCs of Programming_eBook ContentsABCs of Programming_eBook Contents
ABCs of Programming_eBook Contents
Ashley Menhennett
 
Professional JavaScript Development - Creating Reusable Code
Professional JavaScript Development -  Creating Reusable CodeProfessional JavaScript Development -  Creating Reusable Code
Professional JavaScript Development - Creating Reusable Code
Wildan Maulana
 
14922 java script built (1)
14922 java script built (1)14922 java script built (1)
14922 java script built (1)
dineshrana201992
 
Design Patterns in Automation Framework.pdf
Design Patterns in Automation Framework.pdfDesign Patterns in Automation Framework.pdf
Design Patterns in Automation Framework.pdf
ArunVastrad4
 
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptxChapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
Chapter 3 INTRODUCTION TO JAVASCRIPT S.pptx
KelemAlebachew
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
Salman Memon
 
Ad

More from chauhankapil (20)

Gray level transformation
Gray level transformationGray level transformation
Gray level transformation
chauhankapil
 
Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perception
chauhankapil
 
JSP Client Request
JSP Client RequestJSP Client Request
JSP Client Request
chauhankapil
 
Jsp server response
Jsp   server responseJsp   server response
Jsp server response
chauhankapil
 
Markov decision process
Markov decision processMarkov decision process
Markov decision process
chauhankapil
 
RNN basics in deep learning
RNN basics in deep learningRNN basics in deep learning
RNN basics in deep learning
chauhankapil
 
Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)
chauhankapil
 
Bayesian probabilistic interference
Bayesian probabilistic interferenceBayesian probabilistic interference
Bayesian probabilistic interference
chauhankapil
 
Jsp
JspJsp
Jsp
chauhankapil
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
chauhankapil
 
Knowledge acquistion
Knowledge acquistionKnowledge acquistion
Knowledge acquistion
chauhankapil
 
Knowledge based system
Knowledge based systemKnowledge based system
Knowledge based system
chauhankapil
 
Introduction of predicate logics
Introduction of predicate  logicsIntroduction of predicate  logics
Introduction of predicate logics
chauhankapil
 
Types of inheritance in java
Types of inheritance in javaTypes of inheritance in java
Types of inheritance in java
chauhankapil
 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logics
chauhankapil
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
chauhankapil
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
chauhankapil
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
chauhankapil
 
Methods in java
Methods in javaMethods in java
Methods in java
chauhankapil
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
chauhankapil
 
Gray level transformation
Gray level transformationGray level transformation
Gray level transformation
chauhankapil
 
Elements of visual perception
Elements of visual perceptionElements of visual perception
Elements of visual perception
chauhankapil
 
JSP Client Request
JSP Client RequestJSP Client Request
JSP Client Request
chauhankapil
 
Jsp server response
Jsp   server responseJsp   server response
Jsp server response
chauhankapil
 
Markov decision process
Markov decision processMarkov decision process
Markov decision process
chauhankapil
 
RNN basics in deep learning
RNN basics in deep learningRNN basics in deep learning
RNN basics in deep learning
chauhankapil
 
Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)Introduction to generative adversarial networks (GANs)
Introduction to generative adversarial networks (GANs)
chauhankapil
 
Bayesian probabilistic interference
Bayesian probabilistic interferenceBayesian probabilistic interference
Bayesian probabilistic interference
chauhankapil
 
Exception handling in java
Exception handling in javaException handling in java
Exception handling in java
chauhankapil
 
Knowledge acquistion
Knowledge acquistionKnowledge acquistion
Knowledge acquistion
chauhankapil
 
Knowledge based system
Knowledge based systemKnowledge based system
Knowledge based system
chauhankapil
 
Introduction of predicate logics
Introduction of predicate  logicsIntroduction of predicate  logics
Introduction of predicate logics
chauhankapil
 
Types of inheritance in java
Types of inheritance in javaTypes of inheritance in java
Types of inheritance in java
chauhankapil
 
Representation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logicsRepresentation of syntax, semantics and Predicate logics
Representation of syntax, semantics and Predicate logics
chauhankapil
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
chauhankapil
 
Propositional logic
Propositional logicPropositional logic
Propositional logic
chauhankapil
 
Constructors in java
Constructors in javaConstructors in java
Constructors in java
chauhankapil
 
Circular linked list
Circular linked listCircular linked list
Circular linked list
chauhankapil
 
Ad

Recently uploaded (20)

Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
roshinijoga
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Modelling of Concrete Compressive Strength Admixed with GGBFS Using Gene Expr...
Journal of Soft Computing in Civil Engineering
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
Analog electronic circuits with some imp
Analog electronic circuits with some impAnalog electronic circuits with some imp
Analog electronic circuits with some imp
KarthikTG7
 
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Prediction of Flexural Strength of Concrete Produced by Using Pozzolanic Mate...
Journal of Soft Computing in Civil Engineering
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 
Surveying through global positioning system
Surveying through global positioning systemSurveying through global positioning system
Surveying through global positioning system
opneptune5
 
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
Parameter-Efficient Fine-Tuning (PEFT) techniques across language, vision, ge...
roshinijoga
 
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
最新版加拿大魁北克大学蒙特利尔分校毕业证(UQAM毕业证书)原版定制
Taqyea
 
Machine foundation notes for civil engineering students
Machine foundation notes for civil engineering studentsMachine foundation notes for civil engineering students
Machine foundation notes for civil engineering students
DYPCET
 
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software ApplicationsJacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia - Excels In Optimizing Software Applications
Jacob Murphy Australia
 
Control Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptxControl Methods of Noise Pollutions.pptx
Control Methods of Noise Pollutions.pptx
vvsasane
 
Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32Interfacing PMW3901 Optical Flow Sensor with ESP32
Interfacing PMW3901 Optical Flow Sensor with ESP32
CircuitDigest
 
Artificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptxArtificial intelligence and machine learning.pptx
Artificial intelligence and machine learning.pptx
rakshanatarajan005
 
Slide share PPT of NOx control technologies.pptx
Slide share PPT of  NOx control technologies.pptxSlide share PPT of  NOx control technologies.pptx
Slide share PPT of NOx control technologies.pptx
vvsasane
 
Dynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptxDynamics of Structures with Uncertain Properties.pptx
Dynamics of Structures with Uncertain Properties.pptx
University of Glasgow
 
twin tower attack 2001 new york city
twin  tower  attack  2001 new  york citytwin  tower  attack  2001 new  york city
twin tower attack 2001 new york city
harishreemavs
 
Design of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdfDesign of Variable Depth Single-Span Post.pdf
Design of Variable Depth Single-Span Post.pdf
Kamel Farid
 
Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1Computer Security Fundamentals Chapter 1
Computer Security Fundamentals Chapter 1
remoteaimms
 
Analog electronic circuits with some imp
Analog electronic circuits with some impAnalog electronic circuits with some imp
Analog electronic circuits with some imp
KarthikTG7
 
Routing Riverdale - A New Bus Connection
Routing Riverdale - A New Bus ConnectionRouting Riverdale - A New Bus Connection
Routing Riverdale - A New Bus Connection
jzb7232
 
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjjseninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
seninarppt.pptx1bhjiikjhggghjykoirgjuyhhhjj
AjijahamadKhaji
 
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
sss1.pptxsss1.pptxsss1.pptxsss1.pptxsss1.pptx
ajayrm685
 
Slide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptxSlide share PPT of SOx control technologies.pptx
Slide share PPT of SOx control technologies.pptx
vvsasane
 

Java script array

  • 1. JavaScript Arrays Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2. JavaScript Arrays  JavaScript arrays are used to store multiple values in a single variable.  Declaration of an Array There are basically two ways to declare an array. Example:  var House = [ ]; // method 1 var House = new array(); // method 2
  • 3. Example  <html>  <body>  <h2>JavaScript Arrays</h2>  <p id="demo"></p>  <script>  var cars = [“Maruti", “Hundai", "BMW"];  document.getElementById("demo").innerHTML = cars;  </script>  </body>  </html>  Output: JavaScript Arrays  Maruti,Hundai,BMW
  • 4. Creating an Array  Using an array literal is the easiest way to create a JavaScript Array.  Syntax:  var array_name = [item1, item2, ...];
  • 5. Using the JavaScript Keyword new  The following example also creates an Array, and assigns values to it:  <script>  var cars = new Array(“Maruti", “Hundai", "BMW");  document.getElementById("demo").innerHTML = cars;  </script>
  • 6. Access the Elements of an Array  <script>  var cars = [“Maruti", “Hundai", "BMW"];  document.getElementById("demo").innerHTML = cars[0];  </script>  Output: Maruti
  • 7. Changing an Array Element  <script>  var l = [“xy", “yz", “zx"];  l[0] = “ab";  document.getElementById("demo").innerHTML = I;  Output: ab, yz, zx
  • 8. Looping Array Elements  <script>  var fruits, text, fLen, i;  fruits = ["Banana", "Orange", "Apple", "Mango"];  fLen = fruits.length;  text = "<ul>";  for (i = 0; i < fLen; i++) {  text += "<li>" + fruits[i] + "</li>";  }  text += "</ul>";  document.getElementById("demo").innerHTML = text;  </script>  Output:  Banana  Orange  Apple  Mango
  • 9. Access the Full Array  <script>  var shapes = [“circle", “triangle", “square"]; document.getElementById("demo").innerHTML = cars;  </script> Output: circle, triangle, square
  翻译: