0% found this document useful (0 votes)
13 views

Js 2

java script 2

Uploaded by

vijaykharb798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Js 2

java script 2

Uploaded by

vijaykharb798
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Characteristics of Arrays in JavaScript

1.

Indexed Collection:

2.
1. Arrays in JavaScript are zero-indexed, meaning the first element is at index 0, the
second at index 1, and so on.
2. You can access elements using their index, for example, array[0] returns the first
element.
3.

Dynamic Size:

4.

1. Arrays in JavaScript are dynamic, meaning you can add or remove elements without
specifying the size of the array beforehand.
2. The size of the array automatically adjusts as elements are added or removed.

5.

Ordered Data:

6.

1. The order in which elements are inserted into the array is maintained.
2. You can easily rearrange elements by changing their index positions.

7.

Heterogeneous Elements:

8.

1. JavaScript arrays can store different types of data in the same array. For example,
an array can contain numbers, strings, objects, and even other arrays (nested
arrays).

Common Properties and Methods of Arrays

1.

Properties:

2.

1. length: This property gives the number of elements in the array.


3.

Common Methods:

4.

1. push(): Adds one or more elements to the end of an array.


2. pop(): Removes the last element from an array.
3. shift(): Removes the first element from an array.
4. unshift(): Adds one or more elements to the beginning of an array.
5. splice(): Adds or removes elements from an array at a specific index.
6. slice(): Creates a shallow copy of a portion of an array without modifying the
original array.
7. concat(): Merges two or more arrays into a new array.
8. forEach(), map(), filter(), reduce(): Methods used for iterating,
transforming, and manipulating the array elements.

Types of Arrays

1. Single-Dimensional Array:

1. The simplest form of an array where all elements are stored in a single list.

2. Multidimensional Array:

1. Arrays that contain other arrays as elements, creating a matrix or table-like


structure. The most common form is a two-dimensional array, but you can have
arrays with more dimensions.

Array Limitations

1.

Performance:

2.

1. Although JavaScript arrays are generally efficient, manipulating elements at the


beginning of the array (like using shift or unshift) can be less efficient because
it may require shifting the positions of all other elements.

3.

Sparse Arrays:

4.

1. JavaScript allows creating sparse arrays where not all indices have assigned values,
which can lead to unexpected results when performing operations on such arrays.
5.

Data Type Consistency:

6.

1. Unlike some programming languages, JavaScript arrays do not enforce data type
consistency, meaning you can mix different data types in a single array, which can
sometimes lead to confusion or bugs.

Special Types of Arrays

 Typed Arrays:

o JavaScript also supports typed arrays (like Int8Array, Uint8Array,


Float32Array, etc.), which are used to handle binary data in a structured way.
o Typed arrays are used when you need to work with raw binary data and have more
control over how memory is allocated.

You might also like