📲 Download Utility Tools Apps

EMI Calculator

Download EMI Calculator

SOA Games

Download SOA Games

SOA Technology App

Download SOA Technology

BMI Checker

Download BMI Checker

Task Jira

Download Task Jira

Laughing Adda

Download Laughing Adda

📅 हिंदी कैलेंडर ऐप डाउनलोड करें

Download Shubhcalendar App

5️⃣ Arrays in JavaScript

📌 What is an Array?

An array is a collection of values stored in a single variable.

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

🛠️ Creating Arrays

1. Using []

let numbers = [10, 20, 30];

2. Using Array constructor

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

🎯 Accessing Elements

let fruits = ["Apple", "Banana", "Mango"];console.log(fruits[0]); // Apple
console.log(fruits[1]); // Banana

👉 Index starts from 0


⚙️ Basic Array Methods

➕ push() → Add at end

let arr = [1, 2];
arr.push(3);console.log(arr); // [1, 2, 3]

➖ pop() → Remove from end

let arr = [1, 2, 3];
arr.pop();console.log(arr); // [1, 2]

⬅️ shift() → Remove from start

let arr = [1, 2, 3];
arr.shift();console.log(arr); // [2, 3]

➡️ unshift() → Add at start

let arr = [2, 3];
arr.unshift(1);console.log(arr); // [1, 2, 3]

✂️ splice() → Add/Remove/Replace

let arr = [1, 2, 3, 4];// remove 2 elements from index 1
arr.splice(1, 2);console.log(arr); // [1, 4]

👉 Add elements:

let arr = [1, 4];
arr.splice(1, 0, 2, 3);console.log(arr); // [1, 2, 3, 4]

🍰 slice() → Copy part of array

let arr = [1, 2, 3, 4];let newArr = arr.slice(1, 3);console.log(newArr); // [2, 3]

👉 Original array does not change


🚀 Advanced Methods

🔁 map() → Transform array

let numbers = [1, 2, 3];let result = numbers.map(num => num * 2);console.log(result); // [2, 4, 6]

🔍 filter() → Select elements

let numbers = [1, 2, 3, 4];let even = numbers.filter(num => num % 2 === 0);console.log(even); // [2, 4]

➕ reduce() → Single value result

let numbers = [1, 2, 3, 4];let sum = numbers.reduce((total, num) => total + num, 0);console.log(sum); // 10

🔄 forEach() → Loop through array

let fruits = ["Apple", "Banana"];fruits.forEach(fruit => {
console.log(fruit);
});

🧠 Practice Projects

🧑‍🎓 1. Student Marks System

let marks = [80, 75, 90, 60];// total marks
let total = marks.reduce((sum, m) => sum + m, 0);// average
let avg = total / marks.length;// passed students (>= 70)
let passed = marks.filter(m => m >= 70);console.log("Total:", total);
console.log("Average:", avg);
console.log("Passed:", passed);

✅ 2. Todo List

let todos = [];// add task
function addTask(task) {
todos.push(task);
}// remove last task
function removeTask() {
todos.pop();
}// show tasks
function showTasks() {
todos.forEach((task, index) => {
console.log(index + ": " + task);
});
}// usage
addTask("Study JS");
addTask("Practice Arrays");
showTasks();removeTask();
showTasks();


AI Spiritual Tools & Interactive Experiences

Explore powerful AI-driven tools for daily guidance, spirituality, fun quizzes, and self-discovery.

Today’s Quote

Get inspiring daily quotes powered by AI to motivate and guide your day.

Explore Now

AI Tarot Card Reader

Reveal insights about your future, love, and career with AI tarot readings.

Read Tarot

Love Match Calculator

Check compatibility and love predictions using AI-based analysis.

Check Match

Fortune Cookie

Open an AI fortune cookie and receive wisdom, luck, and fun messages.

Open Cookie

Quiz Categories

Engage with knowledge-based and fun quizzes across multiple categories.

Start Quiz

Panchang Calendar

View daily Panchang, auspicious timings, tithi, nakshatra, and festivals.

View Panchang

Online Numerology

Discover your destiny number, life path, and numerology predictions.

Calculate Now

Spiritual Feeds

Stay connected with spiritual thoughts, mantras, and divine content.

View Feeds

Quiz Hub

Attempt trending quizzes on GK, spirituality, festivals, and more.

Explore Quizzes