📘 JavaScript Arrays – Basics
##1️⃣Creating (Defining) an Array
Arrays store multiple values in one variable.
**Syntax:**
```javascript
let arrayName = [item1, item2, item3];
```
**Example:**
```javascript
let fruits = ["Apple", "Banana", "Mango"];
```
---
## Viewing (Accessing) Array Items
2️⃣
Use the index number (starting from 0).
```javascript
[Link](fruits[0]); // Apple (1st item)
[Link](fruits[1]); // Banana (2nd item)
[Link](fruits[2]); // Mango (3rd item)
// View last item
[Link](fruits[[Link] - 1]); // Mango
```
---
## Adding Items to an Array
3️⃣
**a) Add at the End – `.push()`**
```javascript
[Link]("Orange");
```
**b) Add at the Beginning – `.unshift()`**
```javascript
[Link]("Grapes");
```
**c) Add by Index**
```javascript
fruits[2] = "Pineapple";
```
---
## Deleting (Removing) Items
4️⃣
**a) Remove Last Item – `.pop()`**
```javascript
[Link]();
```
**b) Remove First Item – `.shift()`**
```javascript
[Link]();
```
**c) Remove by Index – `.splice(index, count)`**
```javascript
[Link](1, 1); // removes 1 item at index 1
```
---
## Viewing the Whole Array
5️⃣
```javascript
[Link](fruits); // Shows complete array
```
Loop through items:
```javascript
for (let i = 0; i < [Link]; i++) {
[Link](fruits[i]);
## ✅ Quick Recap (Cheat Sheet)
* **Create:** `let fruits = ["Apple", "Banana"];`
* **View:** `fruits[0] → Apple`
* **Add End:** `[Link]("Mango");`
* **Add Start:** `[Link]("Orange");`
* **Delete Last:** `[Link]();`
* **Delete First:** `[Link]();`
* **Delete by Index:** `[Link](1, 1);
Perfect 👍 Here’s a **ready-to-use JavaScript Array Worksheet (Exercises + Solutions)** in simple
student-friendly style.
---
# 📝 **JavaScript Arrays Worksheet**
## 📘 **Part A – Notes (Quick Recap)**
* **Create:** `let fruits = ["Apple", "Banana"];`
* **View:** `fruits[0] → Apple`
* **Add (end):** `[Link]("Mango");`
* **Add (start):** `[Link]("Orange");`
* **Delete (last):** `[Link]();`
* **Delete (first):** `[Link]();`
* **Delete by index:** `[Link](1, 1);`
---
## 🎯 **Part B – Exercises**
### **Q1. Fill in the blanks**
1. The index of the first item in an array is `___`.
2. The method to add an item at the **end** of an array is `______`.
3. The method to remove the **first** item of an array is `______`.
4. In the array `let colors = ["Red", "Blue", "Green"];`, `colors[2]` will give `______`.
---
### **Q2. Predict the output**
```javascript
let fruits = ["Apple", "Banana", "Mango"];
[Link]("Orange");
[Link](fruits);
```
**Answer: \_\_\_\_\_\_\_\_\_\_**
---
### **Q3. Short Coding**
Write code to:
1. Create an array of 3 favorite games.
2. Add one more game at the beginning.
3. Print the first game.
---
### **Q4. Debug the code**
Find and correct the mistake:
```javascript
let cars = ["BMW", "Toyota", "Honda"];
[Link]("Honda");
[Link](cars);
```
*(Hint: does `.pop()` need an argument?)*
---
### **Q5. Real-World Example**
Your teacher wants to store marks of 3 subjects in an array.
1. Create an array `marks = [85, 90, 78]`.
2. Print the second subject’s marks.
---
---
## ✅ **Part C – Solutions (Teacher Use)**
* Q1: 0, push(), shift(), Green
* Q2: `["Apple", "Banana", "Mango", "Orange"]`
* Q3 Example:
```javascript
let games = ["Cricket", "Football", "Hockey"];
[Link]("Chess");
[Link](games[0]);
```
* Q4 Correction:
```javascript
[Link](); // removes last item automatically
```
* Q5:
```javascript
let marks = [85, 90, 78];
[Link](marks[1]); // 90