Thursday 29 April 2021

JavaScript Arrays Tutorial - Introduction and Methods with Examples - map-foreach-sort-some-find-reduce-slice-more

JavaScript Array Methods with Examples - map-foreach-sort-some-find-reduce-slice-more

Arrays Introduction

What is an Array?

An array is a data structure that contains the list of elements in it. It is a single variable in which we can store the elements and access by the variable name along with the index.

How to declare an Array?

We can delcare the array in the below two ways.

1. let employees:string[] = [] // Empty array - Preferred declaration
2. let employees:string[] = new Array() // Empty array

How to declare an Array?

We can delcare the array in the below two ways.

1. let employees:string[] = [] // Empty array - Preferred declaration
2. let employees:string[] = new Array() // Empty array

Array Intialization with declaration:
1. let employees:string[] = ["Jeff Bezos","Elon Musk","Bill Gates","Mark Zuckerberg","Warren Buffett"] // Empty array - Preferred declaration
2. let employees:string[] = new Array("Jeff Bezos","Elon Musk","Bill Gates","Mark Zuckerberg","Warren Buffett") // Empty array

How to access Array Elements?

Array stores the elements by index starting with zero and we can access the elements by the index.

employees[0] // Jeff Bezos - First Element
employees[2] // Bill Gates - Third element
employees[4] // Warren Buffett - Fifth element

Array.length property

Length is the most useful property to determine the array length.
employees.length // 5

Methods or functions

Detailed explanation will follow...

No comments: