Introduction to JavaScript Arrays:
- Arrays store multiple values in a single variable.
- Can hold different data types.
- Indexed starting from 0.
- Ex: array=[1,2,3,4,5]
- Creating an empty array.Ex: arr=[];
- Creating an array and initialise it.
Adding or Removing Items:
- push(): Adds an element to the end.
- pop(): Removes the last element.
- shift(): Removes the first element.
- unshift(): Adds an element to the beginning.
- length: Returns the number of elements.
Iteration Methods:
- ForEach(): Executes a function for each element.
map(): Creates a new array by applying a function.
Reduce():Accumulates values into a single element.
Searching and Filtering:
Extracting / Copying:
- Slice(): Extracts a portion of an array.
Updated Section: Modifying and merging arrays
- splice() – Add, Remove, or Replace (Mutates Original)
- concat() – Merge Arrays (Does NOT Mutate Original)
Conclusion:
- Enhance efficiency and readability to the code.
- Useful for adding,removing, searching,iterating and transforming data.
- JavaScript provides powerful array methods.
Top comments (0)