SlideShare a Scribd company logo
JavaScript Array Methods
Prof. Neeraj Bhargava
Kapil Chauhan
Department of Computer Science
School of Engineering & Systems Sciences
MDS University, Ajmer
JavaScript Array Methods
 Popping
 The pop() method removes the last element from an
array:
 var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.pop();
 Output: Banana,Orange,Apple,Mango
 Banana,Orange,Apple
Pushing
 The push() method adds a new element to an array (at
the end):
 Example
 var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.push("Kiwi");
 Output:Banana,Orange,Apple,Mango,Kiwi
Shifting Elements
 Shifting is equivalent to popping, working on the first
element instead of the last.
 The shift() method removes the first array element
and "shifts" all other elements to a lower index.
 Example
 var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.shift();
 Output: Banana,Orange,Apple,Mango
 Orange,Apple,Mango
Splicing an Array
 The splice() method can be used to add new items to an array:
 Example
 var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.splice(2, 0, "Lemon", "Kiwi");
 The first parameter (2) defines the position where new elements
should be added (spliced in).
 The second parameter (0) defines how many elements should
be removed.
 The rest of the parameters ("Lemon" , "Kiwi") define the new elements
to be added.
 Output:Original Array:
Banana,Orange,Apple,Mango
 New Array:
Banana,Orange,Lemon,Kiwi,Apple,Mango
Merging (Concatenating) Arrays
 The concat() method creates a new array by merging
(concatenating) existing arrays:
 Example (Merging Two Arrays)
 var myGirls = ["Cecilie", "Lone"];
var myBoys = ["Emil", "Tobias", "Linus"];
var myChildren = myGirls.concat(myBoys);
 Output : Cecilie,Lone,Emil,Tobias,Linus
Merging Three Arrays
 var arr1 = ["Cecilie", "Lone"];
var arr2 = ["Emil", "Tobias", "Linus"];
var arr3 = ["Robin", "Morgan"];
var myChildren = arr1.concat(arr2, arr3);
 Output:
Cecilie,Lone,Emil,Tobias,Linus,Robin,Morgan
Slicing an Array
 The slice() method slices out a piece of an array into a new
array.
 This example slices out a part of an array starting from
array element 1 ("Orange"):
 Example
 var fruits =
["Banana", "Orange", "Lemon", "Apple", "Mango"];
var citrus = fruits.slice(1);
 Output: Banana,Orange,Lemon,Apple,Mango
Orange,Lemon,Apple,Mango
Assignment Question
 Explain JavaScript Array Methods with suitable
example.

More Related Content

Similar to Java script array methods (13)

How to add new items in python sets .pptx
How to add new items in python sets .pptxHow to add new items in python sets .pptx
How to add new items in python sets .pptx
AsimMukhtarCheema1
 
Sets
SetsSets
Sets
Lakshmi Sarvani Videla
 
Best Java Problems and Solutions
Best Java Problems and SolutionsBest Java Problems and Solutions
Best Java Problems and Solutions
Java Projects
 
Tuple in python
Tuple in pythonTuple in python
Tuple in python
Sharath Ankrajegowda
 
Lists
ListsLists
Lists
Lakshmi Sarvani Videla
 
List in Python
List in PythonList in Python
List in Python
Sharath Ankrajegowda
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
info309708
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
Nicole Ryan
 
cover every basics of python with this..
cover every basics of python with this..cover every basics of python with this..
cover every basics of python with this..
karkimanish411
 
Python_Sets(1).pptx
Python_Sets(1).pptxPython_Sets(1).pptx
Python_Sets(1).pptx
rishiabes
 
What are arrays in java script
What are arrays in java scriptWhat are arrays in java script
What are arrays in java script
Miguel Silva Loureiro
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
Salman Memon
 
data stracyturwe waaure semeer gorbe eidd fata sahttacuyeiwi
data stracyturwe waaure  semeer gorbe eidd  fata  sahttacuyeiwidata stracyturwe waaure  semeer gorbe eidd  fata  sahttacuyeiwi
data stracyturwe waaure semeer gorbe eidd fata sahttacuyeiwi
husseindabdi1
 
How to add new items in python sets .pptx
How to add new items in python sets .pptxHow to add new items in python sets .pptx
How to add new items in python sets .pptx
AsimMukhtarCheema1
 
Best Java Problems and Solutions
Best Java Problems and SolutionsBest Java Problems and Solutions
Best Java Problems and Solutions
Java Projects
 
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdfGetting StartedCreate a class called Lab8. Use the same setup for .pdf
Getting StartedCreate a class called Lab8. Use the same setup for .pdf
info309708
 
Using arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing informationUsing arrays with PHP for forms and storing information
Using arrays with PHP for forms and storing information
Nicole Ryan
 
cover every basics of python with this..
cover every basics of python with this..cover every basics of python with this..
cover every basics of python with this..
karkimanish411
 
Python_Sets(1).pptx
Python_Sets(1).pptxPython_Sets(1).pptx
Python_Sets(1).pptx
rishiabes
 
PHP Array very Easy Demo
PHP Array very Easy DemoPHP Array very Easy Demo
PHP Array very Easy Demo
Salman Memon
 
data stracyturwe waaure semeer gorbe eidd fata sahttacuyeiwi
data stracyturwe waaure  semeer gorbe eidd  fata  sahttacuyeiwidata stracyturwe waaure  semeer gorbe eidd  fata  sahttacuyeiwi
data stracyturwe waaure semeer gorbe eidd fata sahttacuyeiwi
husseindabdi1
 

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)

May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank22PCOAM16 _ML_Unit 3 Notes & Question bank
22PCOAM16 _ML_Unit 3 Notes & Question bank
Guru Nanak Technical Institutions
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
May 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information TechnologyMay 2025: Top 10 Read Articles Advanced Information Technology
May 2025: Top 10 Read Articles Advanced Information Technology
ijait
 
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptxWeek 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
Week 6- PC HARDWARE AND MAINTENANCE-THEORY.pptx
dayananda54
 
The first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptxThe first edition of the AIAG-VDA FMEA.pptx
The first edition of the AIAG-VDA FMEA.pptx
Mayank Mathur
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-ABB Furse.pdf
djiceramil
 
Structural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant ConversionStructural Design for Residential-to-Restaurant Conversion
Structural Design for Residential-to-Restaurant Conversion
DanielRoman285499
 
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) ProjectMontreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Montreal Dreamin' 25 - Introduction to the MuleSoft AI Chain (MAC) Project
Alexandra N. Martinez
 
SEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair KitSEW make Brake BE05 – BE30 Brake – Repair Kit
SEW make Brake BE05 – BE30 Brake – Repair Kit
projectultramechanix
 
Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)Strength of materials (Thermal stress and strain relationships)
Strength of materials (Thermal stress and strain relationships)
pelumiadigun2006
 
Computer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdfComputer_vision-photometric_image_formation.pdf
Computer_vision-photometric_image_formation.pdf
kumarprem6767merp
 
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdfRearchitecturing a 9-year-old legacy Laravel application.pdf
Rearchitecturing a 9-year-old legacy Laravel application.pdf
Takumi Amitani
 
Flow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docxFlow Chart Proses Bisnis prosscesss.docx
Flow Chart Proses Bisnis prosscesss.docx
rifka575530
 
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptxSemi-Conductor ppt ShubhamSeSemi-Con.pptx
Semi-Conductor ppt ShubhamSeSemi-Con.pptx
studyshubham18
 
Pavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible PavementsPavement and its types, Application of rigid and Flexible Pavements
Pavement and its types, Application of rigid and Flexible Pavements
Sakthivel M
 
How Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdfHow Binning Affects LED Performance & Consistency.pdf
How Binning Affects LED Performance & Consistency.pdf
Mina Anis
 
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdfIrja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus - Beyond Pass and Fail - DevTalks.pdf
Irja Straus
 
New Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docxNew Microsoft Office Word Documentfrf.docx
New Microsoft Office Word Documentfrf.docx
misheetasah
 
Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401Universal Human Values and professional ethics Quantum AKTU BVE401
Universal Human Values and professional ethics Quantum AKTU BVE401
Unknown
 
Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.Third Review PPT that consists of the project d etails like abstract.
Third Review PPT that consists of the project d etails like abstract.
Sowndarya6
 
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
362 Alec Data Center Solutions-Slysium Data Center-AUH-Adaptaflex.pdf
djiceramil
 
Ad

Java script array methods

  • 1. JavaScript Array Methods Prof. Neeraj Bhargava Kapil Chauhan Department of Computer Science School of Engineering & Systems Sciences MDS University, Ajmer
  • 2. JavaScript Array Methods  Popping  The pop() method removes the last element from an array:  var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.pop();  Output: Banana,Orange,Apple,Mango  Banana,Orange,Apple
  • 3. Pushing  The push() method adds a new element to an array (at the end):  Example  var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.push("Kiwi");  Output:Banana,Orange,Apple,Mango,Kiwi
  • 4. Shifting Elements  Shifting is equivalent to popping, working on the first element instead of the last.  The shift() method removes the first array element and "shifts" all other elements to a lower index.  Example  var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.shift();  Output: Banana,Orange,Apple,Mango  Orange,Apple,Mango
  • 5. Splicing an Array  The splice() method can be used to add new items to an array:  Example  var fruits = ["Banana", "Orange", "Apple", "Mango"]; fruits.splice(2, 0, "Lemon", "Kiwi");  The first parameter (2) defines the position where new elements should be added (spliced in).  The second parameter (0) defines how many elements should be removed.  The rest of the parameters ("Lemon" , "Kiwi") define the new elements to be added.  Output:Original Array: Banana,Orange,Apple,Mango  New Array: Banana,Orange,Lemon,Kiwi,Apple,Mango
  • 6. Merging (Concatenating) Arrays  The concat() method creates a new array by merging (concatenating) existing arrays:  Example (Merging Two Arrays)  var myGirls = ["Cecilie", "Lone"]; var myBoys = ["Emil", "Tobias", "Linus"]; var myChildren = myGirls.concat(myBoys);  Output : Cecilie,Lone,Emil,Tobias,Linus
  • 7. Merging Three Arrays  var arr1 = ["Cecilie", "Lone"]; var arr2 = ["Emil", "Tobias", "Linus"]; var arr3 = ["Robin", "Morgan"]; var myChildren = arr1.concat(arr2, arr3);  Output: Cecilie,Lone,Emil,Tobias,Linus,Robin,Morgan
  • 8. Slicing an Array  The slice() method slices out a piece of an array into a new array.  This example slices out a part of an array starting from array element 1 ("Orange"):  Example  var fruits = ["Banana", "Orange", "Lemon", "Apple", "Mango"]; var citrus = fruits.slice(1);  Output: Banana,Orange,Lemon,Apple,Mango Orange,Lemon,Apple,Mango
  • 9. Assignment Question  Explain JavaScript Array Methods with suitable example.