WELCOME
Group Members 
• M.Tayyab 
• Hassan Dar 
• Saddam Butt 
• Bilal Khan
TOPICS 
• Arrays 
• Declaring and Allocating Array 
• Types of Array 
• Array Methods 
• Array Attributes
Arrays 
• Array inherits from Object. 
• Indexes are converted to strings and 
used as names for retrieving values. 
• Very efficient for sparse arrays. 
• Not very efficient in most other cases. 
• One advantage: No need to provide a 
length or type when creating an array.
Declaring and Allocating Arrays 
• JavaScript arrays are Array objects. 
• Creating new objects using the new 
operator is known as creating an 
instance or instantiating an object 
• Operator new is known as the dynamic 
memory allocation operator
Declare + Initialize Arrays 
var array_name = [“a” , ”b” , ”c”]; 
Using the JavaScript Keyword new
Types of Array 
• Associative Array 
• Index Array
Associative Array 
(keys and values) var person = []; 
person [“ firstName "] = “Hassan"; 
person [“ lastName "] = "Dar"; 
OR
Indexing Array 
Array elements are accessed using their index number: 
var ary = [“A” , “B” , “C” , “D” , “E” , “F”]; 
document.write(ary[4]); //output : E
USING LOOP
Array Methods 
• Concat 
• Join 
• Push 
• Pop 
• UnShift 
• Shift 
• Sort 
• Slice 
• Splice
CONCAT
Join 
The join() method also joins all array elements into 
a string. 
It behaves just like toString(), but you can specify 
the separator:
PUSH 
The push() method adds a new element to an 
array (at the end):
POP 
The pop() method removes the last 
element from an array:
UNSHIFT
SHIFT
SORT
REVERSE
SLICE…
SLICE
SPLICE 
The splice() method can be used to add new items to 
an array and also Remove items from Array: 
Add Values
Remove Values
ADD & REMOVE
Array Attributes 
•length 
•indexOf 
•typeOf 
M 
•Changing Elements 
•Deleting Elements
LENGTH….. 
• The length property provides an 
easy way to append new elements 
to an array without using the 
push() method.
LENGTH
INDEXOF
Typeof 
A common question is: How do I know if a variable 
is an array? The problem is that the JavaScript 
operator typeof returns "object":
Changing Elements
Deleting Elements 
delete array[number] 
• Removes the element, but leaves 
a hole in the numbering. 
array.splice(number, 1) 
• Removes the element and 
renumbers all the following 
elements.
Deleting Elements 
Ary = ['a', 'b', 'c', 'd‘ ,‘e’]; 
delete Ary[1]; 
['a',undefined, 'c', 'd‘ ,’e’]
THANKS 
FOR 
WATCHING

Javascript arrays

  • 1.
  • 2.
    Group Members •M.Tayyab • Hassan Dar • Saddam Butt • Bilal Khan
  • 3.
    TOPICS • Arrays • Declaring and Allocating Array • Types of Array • Array Methods • Array Attributes
  • 4.
    Arrays • Arrayinherits from Object. • Indexes are converted to strings and used as names for retrieving values. • Very efficient for sparse arrays. • Not very efficient in most other cases. • One advantage: No need to provide a length or type when creating an array.
  • 5.
    Declaring and AllocatingArrays • JavaScript arrays are Array objects. • Creating new objects using the new operator is known as creating an instance or instantiating an object • Operator new is known as the dynamic memory allocation operator
  • 6.
    Declare + InitializeArrays var array_name = [“a” , ”b” , ”c”]; Using the JavaScript Keyword new
  • 7.
    Types of Array • Associative Array • Index Array
  • 8.
    Associative Array (keysand values) var person = []; person [“ firstName "] = “Hassan"; person [“ lastName "] = "Dar"; OR
  • 9.
    Indexing Array Arrayelements are accessed using their index number: var ary = [“A” , “B” , “C” , “D” , “E” , “F”]; document.write(ary[4]); //output : E
  • 10.
  • 11.
    Array Methods •Concat • Join • Push • Pop • UnShift • Shift • Sort • Slice • Splice
  • 12.
  • 13.
    Join The join()method also joins all array elements into a string. It behaves just like toString(), but you can specify the separator:
  • 14.
    PUSH The push()method adds a new element to an array (at the end):
  • 15.
    POP The pop()method removes the last element from an array:
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
    SPLICE The splice()method can be used to add new items to an array and also Remove items from Array: Add Values
  • 23.
  • 24.
  • 25.
    Array Attributes •length •indexOf •typeOf M •Changing Elements •Deleting Elements
  • 26.
    LENGTH….. • Thelength property provides an easy way to append new elements to an array without using the push() method.
  • 27.
  • 28.
  • 29.
    Typeof A commonquestion is: How do I know if a variable is an array? The problem is that the JavaScript operator typeof returns "object":
  • 30.
  • 31.
    Deleting Elements deletearray[number] • Removes the element, but leaves a hole in the numbering. array.splice(number, 1) • Removes the element and renumbers all the following elements.
  • 32.
    Deleting Elements Ary= ['a', 'b', 'c', 'd‘ ,‘e’]; delete Ary[1]; ['a',undefined, 'c', 'd‘ ,’e’]
  • 33.