[go: up one dir, main page]

0% found this document useful (0 votes)
2 views17 pages

Javascriptarrays 141202114627 Conversion Gate01

The document provides an overview of arrays in JavaScript, including their declaration, allocation, types, and methods. It explains the differences between associative and index arrays, as well as array attributes like length and indexOf. Additionally, it covers how to change and delete elements within an array.

Uploaded by

brokenhero267
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views17 pages

Javascriptarrays 141202114627 Conversion Gate01

The document provides an overview of arrays in JavaScript, including their declaration, allocation, types, and methods. It explains the differences between associative and index arrays, as well as array attributes like length and indexOf. Additionally, it covers how to change and delete elements within an array.

Uploaded by

brokenhero267
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 17

WELCOME

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 Attributes
• length
• indexOf
• typeOf
• 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’]

You might also like