Web Development - HTML, CSS & JavaScript
55.4K subscribers
1.93K photos
5 videos
34 files
538 links
Learn to code and become a Web Developer with HTML, CSS, JavaScript , Reactjs, Wordpress, PHP, Mern & Nodejs knowledge

Managed by: @love_data
Download Telegram
๐Ÿ’ป JavaScript Learning Series: Day 7

Topic 7: Arrays in JavaScript

Arrays are one of the most important concepts in JavaScript.

An array is a special type of object used to store multiple values in a single variable.

Instead of creating separate variables for every value, you can store them together in an array.

Example:

Without an array:

let fruit1 = "Apple";
let fruit2 = "Mango";
let fruit3 = "Banana";


Using an array:

let fruits = ["Apple", "Mango", "Banana"];

console.log(fruits);


Output:

["Apple", "Mango", "Banana"]


Let's understand arrays step by step.

1. Creating an Array

You can create an array using square brackets [].

let fruits = ["Apple", "Mango", "Banana"];
let numbers = [10, 20, 30, 40];
let mixed = ["Rahul", 25, true, 50000];

console.log(fruits);
console.log(numbers);
console.log(mixed);


JavaScript arrays can contain different data types.

You can also create an array using the Array constructor:

let numbers = new Array(10, 20, 30);

console.log(numbers);


2. Accessing Array Elements

Array elements are accessed using their index positions.

Important: JavaScript arrays use zero-based indexing.

โ€ข First element โžœ Index 0

โ€ข Second element โžœ Index 1

โ€ข Third element โžœ Index 2

โ€ข Fourth element โžœ Index 3

Example:

console.log(fruits[0]);
console.log(fruits[1]);
console.log(fruits[2]);


Output:

Apple
Mango
Banana


3. Modifying Array Elements

You can change an array element by accessing its index.

fruits[1] = "Orange";
console.log(fruits);


Output:

["Apple", "Orange", "Banana"]


The element at index 1 has been replaced.

4. Finding Array Length

The length property returns the total number of elements in an array.

console.log(fruits.length);


Output: 3

You can also use it to access the last element:

let lastFruit = fruits[fruits.length - 1];

console.log(lastFruit);


Output: Banana

5. Adding Elements to an Array

JavaScript provides several methods to add elements.

A. push()

Adds an element at the end of an array.

let fruits = ["Apple", "Mango"];

fruits.push("Banana");
console.log(fruits);


Output: ["Apple", "Mango", "Banana"]

B. unshift()

Adds an element at the beginning of an array.

fruits.unshift("Banana");
console.log(fruits);


Output: ["Banana", "Apple", "Mango"]

6. Removing Elements from an Array

A. pop()

Removes the last element.

fruits.pop();
console.log(fruits);


Output: ["Apple", "Mango"]

B. shift()

Removes the first element.

fruits.shift();
console.log(fruits);


Output: ["Mango", "Banana"]

7. Important Array Methods

Let's understand some commonly used array methods.

A. indexOf()

Returns the first index of a specified element, or -1 if it is not found.

console.log(fruits.indexOf("Mango"));


Output: 1

B. includes()

Checks whether an array contains a particular element.

console.log(fruits.includes("Mango"));


Output: true

C. slice()

Returns a portion of an array without modifying the original array.
โค1
let numbers = [10, 20, 30, 40, 50];

let result = numbers.slice(1, 4);

console.log(result);


Output: [20, 30, 40]

D. splice()

Adds, removes, or replaces elements in the original array.

fruits.splice(1, 1, "Orange");
console.log(fruits);


Output: ["Apple", "Orange", "Banana"]

Here:

โ€ข 1 โžœ Starting index.

โ€ข 1 โžœ Number of elements to remove.

โ€ข "Orange" โžœ New element to insert.

8. Iterating Through Arrays

You can use loops to access every element in an array.

A. Using for Loop

for (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}


B. Using for...of

for (let fruit of fruits) {
console.log(fruit);
}


C. Using forEach()

Executes a callback function for each array element.

let numbers = [10, 20, 30];

numbers.forEach(function(num) {
console.log(num);
});


9. map() Method

The map() method creates a new array by transforming every element of the original array.

Example: Multiply Every Number by 2

let numbers = [1, 2, 3, 4, 5];

let result = numbers.map(num => num * 2);

console.log(result);


Output:

[2, 4, 6, 8, 10]


Use case: Transforming data, formatting values, and preparing information for display.

10. filter() Method

The filter() method creates a new array containing elements that satisfy a given condition.

Example: Find Even Numbers

let numbers = [1, 2, 3, 4, 5, 6];

let result = numbers.filter(num => num % 2 === 0);

console.log(result);


Output:

[2, 4, 6]


Use case: Filtering products, employees, customers, and records based on conditions.

11. reduce() Method

The reduce() method processes array elements and combines them into a single accumulated result.

Example: Calculate Total

let numbers = [10, 20, 30, 40];

let total = numbers.reduce((sum, num) => {
return sum + num;
}, 0);

console.log(total);


Output: 100

Use case: Calculating totals, sums, averages, and aggregations.

12. find() Method

Returns the first element that satisfies a specified condition.

let numbers = [10, 20, 30, 40];
let result = numbers.find(num => num > 20);

console.log(result);


Output: 30

Unlike filter(), find() returns only the first matching element.

13. sort() Method

Used to sort array elements.

let numbers = [40, 10, 30, 20];

numbers.sort((a, b) => a - b);
console.log(numbers);


Output: [10, 20, 30, 40]

For descending order:

numbers.sort((a, b) => b - a);
console.log(numbers);


Important: Calling sort() directly without a comparator sorts elements as strings by default.

14. Joining Array Elements

The join() method combines array elements into a single string.

let result = fruits.join(", ");
console.log(result);


Output:

Apple, Mango, Banana


15. Multidimensional Arrays

A multidimensional array contains other arrays as elements.

let numbers = [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9]
];

console.log(numbers[0][1]);
console.log(numbers[2][2]);


Output:

2
9
These arrays are useful for matrices, tables, grids, and structured datasets.

16. Arrays of Objects

In real-world applications, arrays frequently store multiple objects.

Example: Employee Records

let employees = [
{
name: "Rahul",
salary: 50000
},
{
name: "Priya",
salary: 60000
},
{
name: "Amit",
salary: 45000
}
];

console.log(employees[0].name);
console.log(employees[1].salary);


Output:

Rahul
60000


You can also filter employees based on salary:

let highSalary = employees.filter(
emp => emp.salary > 50000
);

console.log(highSalary);


This is commonly used when working with API responses and business applications.

17. Real-World Example: Shopping Cart

Let's build a simple shopping cart using JavaScript arrays.

let cart = [
{ name: "Laptop", price: 50000 },
{ name: "Mouse", price: 1000 },
{ name: "Keyboard", price: 2000 }
];

let total = cart.reduce((sum, item) => {
return sum + item.price;
}, 0);

console.log("Cart Items:", cart.length);
console.log("Total Amount:", total);


Output:

Cart Items: 3
Total Amount: 53000


This example combines arrays, objects, and the reduce() method.

18. Important Array Methods, Quick Revision

๐Ÿ”น push() โžœ Adds an element at the end.

๐Ÿ”น pop() โžœ Removes the last element.

๐Ÿ”น shift() โžœ Removes the first element.

๐Ÿ”น unshift() โžœ Adds an element at the beginning.

๐Ÿ”น map() โžœ Transforms every element and returns a new array.

๐Ÿ”น filter() โžœ Returns elements matching a condition.

๐Ÿ”น reduce() โžœ Combines elements into a single result.

๐Ÿ”น forEach() โžœ Executes a function for every element.

๐Ÿ”น find() โžœ Returns the first matching element.

๐Ÿ”น includes() โžœ Checks whether an element exists.

๐Ÿ”น indexOf() โžœ Returns the first matching index.

๐Ÿ”น slice() โžœ Extracts a portion without modifying the original array.

๐Ÿ”น splice() โžœ Adds, removes, or replaces elements in the original array.

๐Ÿ”น sort() โžœ Sorts array elements.

๐Ÿ”น join() โžœ Converts array elements into a string.

Double Tap โค๏ธ For More
โค1
๐—™๐—ฅ๐—˜๐—˜ ๐—Ÿ๐—˜๐—”๐—ฅ๐—ก๐—œ๐—ก๐—š ๐—”๐—ก๐—— ๐—–๐—˜๐—ฅ๐—ง๐—œ๐—™๐—œ๐—–๐—”๐—ง๐—œ๐—ข๐—ก ๐—ฅ๐—˜๐—ฆ๐—ข๐—จ๐—ฅ๐—–๐—˜๐—ฆ ๐—ง๐—ข ๐—•๐—จ๐—œ๐—Ÿ๐—— ๐—ฌ๐—ข๐—จ๐—ฅ ๐—–๐—ข๐——๐—œ๐—ก๐—š ๐—ฆ๐—ž๐—œ๐—Ÿ๐—Ÿ๐—ฆ๐Ÿ˜

Explore free courses and resources to learn:

โœ… Beginner-Friendly Resources
โœ… Self-Paced Learning
โœ… Build Practical Coding Skills
โœ… Explore Certification Opportunities

๐ŸŽฏ Perfect for Students, Freshers & Aspiring Developers!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/4fbyA6I

๐Ÿ“Œ SAVE & SHARE with friends looking for FREE courses๐Ÿ”ฅ
๐ŸŒ Web Development Tips for Beginners

Starting web development can feel overwhelming because there are so many technologies to learn.

HTML, CSS, JavaScript, React, Node.js, databases, Git, APIsโ€ฆ ๐Ÿ˜ตโ€๐Ÿ’ซ

The key is not to learn everything at once.

Here are some practical tips that can make your journey much easier ๐Ÿ‘‡

1๏ธโƒฃ Master the Basics Before Frameworks

Don't rush into React just because everyone is talking about it.

First understand:

HTML โ†’ Structure

CSS โ†’ Styling

JavaScript โ†’ Logic

Once these are clear, frameworks become much easier to understand.

2๏ธโƒฃ Don't Just Watch Tutorials

Watching 100 hours of tutorials won't make you a developer.

After learning a concept, immediately build something with it.

For example:

Learn Forms

โ†“

Build a Registration Form

Learn DOM

โ†“

Build a To-Do List

Learn APIs

โ†“

Build a Weather App

๐Ÿ‘‰ Learn โ†’ Build โ†’ Break โ†’ Fix โ†’ Repeat.

3๏ธโƒฃ Learn by Building Small Projects

Don't start with:

โŒ "I'll build the next Amazon."

Start with:

โœ” Calculator

โœ” To-Do App

โœ” Quiz App

โœ” Weather App

โœ” Expense Tracker

โœ” Notes App

โœ” Portfolio Website

Small projects teach you how to actually solve problems.

4๏ธโƒฃ Learn JavaScript Properly

JavaScript is one of the most important skills in modern web development.

Focus on:

Variables

Functions

Arrays

Objects

Loops

DOM

Events

Promises

Async/Await

Fetch API

ES6+

Modules

Error Handling

Don't just memorize syntax.

Understand why and when to use each concept.

5๏ธโƒฃ Learn to Read Documentation

A professional developer doesn't Google every problem and copy the first answer.

Learn to use official documentation.

When you encounter a problem:

Understand the problem

โ†“

Search documentation

โ†“

Try a solution

โ†“

Test it

โ†“

Understand why it works

This skill becomes extremely valuable as you progress.

6๏ธโƒฃ Get Comfortable With Developer Tools

Learn to use your browser's DevTools.

Important sections include:

Elements

Console

Network

Application

Sources

For example, if an API isn't working, the Network tab can help you inspect:

Request

Response

Status code

Headers

Payload

7๏ธโƒฃ Learn Git Early

Don't wait until you're applying for jobs.

Learn basic Git commands:

git init

git add .

git commit -m "Initial commit"

git status

git push

git pull

Use GitHub to maintain your projects.

Your GitHub profile can become part of your developer portfolio.

8๏ธโƒฃ Understand How Websites Actually Work

Don't just learn code.

Understand the fundamentals:

Browser

โ†“

HTTP Request

โ†“

Server

โ†“

Database

โ†“

Server Response

โ†“

Browser

Learn the basics of:

HTTP

URLs

DNS

APIs

JSON

Status codes

Client vs Server

Databases

This knowledge makes full-stack development much easier.

9๏ธโƒฃ Don't Copy-Paste Code You Don't Understand

You can use AI tools and online resources.

But avoid blindly copying code.

If you get:

fetch("/api/users")

understand:

What is fetch()?

What is an API?

What does /api/users represent?

What does the response contain?

What happens if the request fails?

Understanding matters more than typing.

๐Ÿ”Ÿ Learn Debugging

Errors are not failures.

They are clues.

When you see:

404

500

TypeError

SyntaxError

undefined

Don't immediately delete your code.

Read the error.

Ask:

What happened?
โค4๐Ÿ‘1
Where did it happen?

Why did it happen?

How can I reproduce it?

How can I fix it?

Debugging is one of the most important developer skills.

1๏ธโƒฃ1๏ธโƒฃ Make Your Projects Responsive

A website shouldn't look good only on your laptop.

Test it on:

๐Ÿ“ฑ Mobile

๐Ÿ“ฑ Tablet

๐Ÿ’ป Laptop

๐Ÿ–ฅ๏ธ Desktop

Learn:

Flexbox

CSS Grid

Media Queries

Responsive Units

1๏ธโƒฃ2๏ธโƒฃ Build Projects Without Following Tutorials

Tutorial projects are useful initially.

But eventually, close the tutorial and build something yourself.

For example:

Tutorial:

Build a To-Do App

Your Version:

Build an Expense Tracker

This forces you to think instead of follow instructions.

1๏ธโƒฃ3๏ธโƒฃ Deploy Your Projects

A project sitting only on your laptop doesn't demonstrate deployment skills.

Learn how to deploy your applications.

For example:

Code

โ†“

GitHub

โ†“

Deployment Platform

โ†“

Live Website ๐ŸŒ

Add the live link to your portfolio.

1๏ธโƒฃ4๏ธโƒฃ Don't Learn Too Many Technologies at Once

Avoid this:

HTML

CSS

JavaScript

React

Angular

Vue

Node

Django

Java

Python

PHP

MongoDB

AWS

Docker

Kubernetes

๐Ÿ˜ตโ€๐Ÿ’ซ

Instead:

HTML

โ†“

CSS

โ†“

JavaScript

โ†“

React

โ†“

Node.js

โ†“

Database

โ†“

Deployment

Build a strong foundation before expanding.

1๏ธโƒฃ5๏ธโƒฃ Create a Portfolio

Your portfolio should show:

About

Skills

Projects

GitHub

Live Projects

Contact

For every major project, explain:

โ€ข What problem it solves

โ€ข Technologies used

โ€ข Key features

โ€ข Challenges faced

โ€ข What you learned

โ€ข Live demo

โ€ข GitHub repository

๐Ÿง  Don't compare your Day 10 with someone's Year 5.

You will:

Get confused

โ†“

Make mistakes

โ†“

Get stuck

โ†“

Debug

โ†“

Understand

โ†“

Improve

That's normal.

Every developer goes through this process.

๐Ÿš€ Double Tap โค๏ธ For More
โค15
๐—™๐—ฅ๐—˜๐—˜ ๐— ๐—ฎ๐˜€๐˜๐—ฒ๐—ฟ๐—ฐ๐—น๐—ฎ๐˜€๐˜€ ๐—ข๐—ป ๐—Ÿ๐—ฎ๐˜๐—ฒ๐˜€๐˜ ๐—ง๐—ฒ๐—ฐ๐—ต๐—ป๐—ผ๐—น๐—ผ๐—ด๐—ถ๐—ฒ๐˜€ ๐Ÿ˜

Get the 90-Day Plan to Build 1% Tech Career

- AI
- GenAI
- Data Analytics
- Fullstack
- UI/UX

Use Coupon Code " ๐—›๐—–๐—Ÿ๐—š๐—จ๐—ฉ๐—œ๐Ÿญ๐Ÿฌ๐Ÿฌ " To Register For FREE

๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฒ๐—ฟ ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜๐Ÿ‘‡ :-

https://pdlink.in/4fFMe22

Date:- 21st Nov 2026 Time:- 5:00 PM (IST)
โค1
๐—•๐—ข๐—ข๐—ฆ๐—ง ๐—ฌ๐—ข๐—จ๐—ฅ ๐—ฅ๐—˜๐—ฆ๐—จ๐— ๐—˜ ๐—ช๐—œ๐—ง๐—› ๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐—œ๐—ก-๐——๐—˜๐— ๐—”๐—ก๐—— ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ! ๐ŸŽ“

๐Ÿ˜ Want to learn high-demand tech skills without spending โ‚น1?

๐Ÿ“Š Data Analytics
๐Ÿ’ป Full Stack Development
๐Ÿค– AI & Generative AI
โ˜๏ธ Cloud Computing

๐ŸŽฏPerfect for Students, Freshers & Job Seekers!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/4jsqetS

๐Ÿ“Œ SAVE & SHARE with friends looking for FREE courses๐Ÿ”ฅ
๐—–๐—œ๐—ฆ๐—–๐—ข ๐—™๐—ฅ๐—˜๐—˜ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! ๐ŸŽ“

Boost your Resume & LinkedIn Profile with valuable tech skills

Explore FREE Cisco learning resources! ๐Ÿš€

๐ŸŒ Networking Fundamentals
๐Ÿ” Cybersecurity
โ˜๏ธ Cloud & DevOps
๐Ÿ’ป IT Fundamentals

๐ŸŽฏ Perfect for Students, Freshers & Job Seekers!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/3WPl0Qg

๐Ÿ“Œ SAVE & SHARE with friends interested in Tech Careers! ๐Ÿ”ฅ
โค2
๐Ÿš€ ๐—ง๐—ข๐—ฃ ๐Ÿฐ ๐—™๐—ฅ๐—˜๐—˜ ๐——๐—˜๐—ฉ๐—ข๐—ฃ๐—ฆ ๐—–๐—ข๐—จ๐—ฅ๐—ฆ๐—˜๐—ฆ ๐Ÿฎ๐Ÿฌ๐Ÿฎ๐Ÿฒ! โ˜๏ธ

๐ŸŽ“ Explore 4 FREE learning resources to build valuable DevOps skills!

โœ… Beginner-Friendly Resources
โœ… Learn at Your Own Pace
โœ… Build In-Demand Technical Skills

๐ŸŽฏ Perfect for Students, Freshers & Aspiring DevOps Engineers!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/3WKDbGO

๐Ÿ“Œ SAVE & SHARE with friends interested in DevOps careers! ๐Ÿ”ฅ
โค1
๐—ง๐—ข๐—ฃ ๐Ÿฑ ๐—™๐—ฅ๐—˜๐—˜ ๐—ฅ๐—˜๐—ฆ๐—ข๐—จ๐—ฅ๐—–๐—˜๐—ฆ ๐—ง๐—ข ๐— ๐—”๐—ฆ๐—ง๐—˜๐—ฅ ๐—ฆ๐—ค๐—Ÿ! ๐Ÿ“Š

Discover 5 FREE learning resources to make SQL easier to understand!

โœ… SQL Basics & Queries
โœ… Joins & Subqueries
โœ… GROUP BY & Window Functions
โœ… Hands-On SQL Practice
โœ… Interview Preparation

๐ŸŽฏ Perfect for Students, Freshers & Aspiring Data Analysts!

๐—Ÿ๐—ถ๐—ป๐—ธ๐Ÿ‘‡:-

https://pdlink.in/4CoB4J2

๐Ÿ“Œ SAVE & SHARE with friends learning SQL! ๐Ÿ”ฅ
โค1
๐Ÿš€ ๐—œ๐—ป๐—ฑ๐—ถ๐—ฎ ๐—”๐—œ ๐—ข๐—ฝ๐—ฒ๐—ป | ๐—ง๐˜‚๐—ฟ๐—ป ๐˜†๐—ผ๐˜‚๐—ฟ ๐—”๐—œ ๐˜€๐—ธ๐—ถ๐—น๐—น๐˜€ ๐—ถ๐—ป๐˜๐—ผ ๐—ฎ ๐—ฐ๐—ฎ๐—ฟ๐—ฒ๐—ฒ๐—ฟ ๐—ผ๐—ฝ๐—ฝ๐—ผ๐—ฟ๐˜๐˜‚๐—ป๐—ถ๐˜๐˜†๐Ÿ˜

Internships paying up to โ‚น1 lakh/month and full-time roles offering up to โ‚น50 LPA.

๐Ÿ† โ‚น50,000 for first place ยท โ‚น1.2 lakh in total cash prizes across the top 20

๐Ÿ“… 12โ€“13 December ยท Round 1 test and interview

๐—ฅ๐—ฒ๐—ด๐—ถ๐˜€๐˜๐—ฒ๐—ฟ ๐—™๐—ผ๐—ฟ ๐—™๐—ฅ๐—˜๐—˜ ๐Ÿ‘‡:-

https://pdlink.in/4APQjZN

๐Ÿ“Œ Save the dates and share this with a friend whoโ€™s building with AI.
โค3
โŒจ๏ธ JavaScript Neat Tricks you should know
โค5