Hi everyone ! In this blog , we will discuss about Array and its method in JavaScript that commonly used nowadays that will help you to improve your production code and expand your knowledge .
Topics to Cover :
- Datatypes
- What is Array and why to use it
- Array methods :
- push() and pop()
- shift() and unshift()
- map()
- filter()
- reduce() (basic explanation only)
- forEach()
Datatypes
In JavaScript , Datatypes defines what kind of value you can hold inside a variable.
Think of data types like different types of containers in real life :
- A water bottle holds water
- A wallet holds money
- A folder holds document
There are 8 different kind of datatypes in JavaScript.
1. String :- Text inside quotes
eg:- let name = "Like this blog"
2. Boolean :- Only two values
eg:- True , False
3. BigInt :- For very very large numbers.
eg:- let bigNumber = 12345678901234567890n;
4. Number :- Any normal number.
eg:- let marks = 95;
let price = 99.99;
5. Undefined :- When a variable and no value is given
eg:- let x;
6. Symbol :- Creates a unique value.
eg:- let id = Symbol("id");
7. Null :- Means intentionally empty.
eg:- let data = null;
8. Object :- Stores multiple values together
eg:- let user = {
name: "Kunal",
age: 21
};
Note :- In JavaScript datatype of Array is object.
Array and why to use array
An Array is a data structure that contains list of element which store multiple value under a single variable.
To declare an Array in JavaScript you can use let , var , const keywords with square bracket and enclose all the element with them.
let items = ["like" , "This" , "blog"]
In JavaScript you can assign any datatypes inside an array.
But why we use Array ?
We use array for the following :
- To store multiple values inside one variable
- To access item using index ( position )
- To loop through data easily
Array Methods Every Developer Should Know
Array are the fundamental part of programming language. They allow you to store , manipulate and access multiple values in a single variable
Array do have some inbuilt methods that helps us to manipulate the Array easily
Lets see one by one
1. push() and pop()
- push() :- The push() methods adds one or more elements to the end of an array
- pop() :- The pop() method removes the last element of an array
2. shift() and unshift()
- shift() :- Similar to push and pop , shift() removes the first element of an array
- unshift() :- unshift() add one or more element to the beginning of array
3. map()
The map() method creates a new array by applying a function to each element of the original array.
4. filter()
The filter() method creates a new array with all elements that pass the condition provided by the function.
Note :- It will only return the element with fulfill the condition of the function rest will be ignored.
5. reduce()
The reduce() method executes a reducer function on each element of the array, reducing in single output value.
6. forEach()
The forEach() method executes a provided function once for each array element.
These methods provide powerful tools for managing and manipulating data structures more effectively. As you integrate these methods into your daily coding practices, you’ll find they can dramatically improve the quality and readability of your code, enabling you to build more efficient products.
Thanks for reading ! if enjoyed this blog , you can read more on this 👇









Top comments (0)