MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
Array Basics and Methods0%
Study Materials
JavaScript for BeginnersProgress 0%
1.1What is JavaScript?1.2How JavaScript Works in Browser1.3Setting up Environment: VSCode, Live Server
8.1Array Basics and Methods8.2Object Basics and Properties8.3Iterating over Arrays and Objects
HomeTutorialsJavaScript for BeginnersArray Basics and Methods
Object Basics and Properties

Array Basics and Methods

Beginner12 min read•Updated: 2026-09-15•By Er. Sumit Kumar (MSK Institute)
Study Materials

An Array is an ordered, zero-indexed list of values. Arrays in JavaScript are dynamic: they can grow or shrink in size and hold any mixture of data types (strings, numbers, objects, even other arrays).


1. Creating and Accessing Arrays

1// Array literal syntax (Standard):
2const fruits = ["Apple", "Banana", "Mango", "Orange"];
3 
4// Accessing elements (Zero-indexed):
5console.log(fruits[0]); // "Apple"
6console.log(fruits[2]); // "Mango"
7 
8// Array length:
9console.log(fruits.length); // 4
10 
11// Modern .at() method for negative indexing:
12console.log(fruits.at(-1)); // "Orange" (Last element!)

2. Mutating Arrays: Add & Remove Elements

Git, games, and web forms frequently add and remove list items. JavaScript provides four primary stack/queue methods:

1 unshift() [Add to Front] push() [Add to End]
2 \ /
3 [ Item 1 , Item 2 , Item 3 ]
4 / \
5 shift() [Remove Front] pop() [Remove End]

Methods Summary:

1const tasks = ["Study HTML", "Learn CSS"];
2 
3// 1. push() - Adds one or more elements to the END (Returns new length)
4tasks.push("Master JS");
5console.log(tasks); // ["Study HTML", "Learn CSS", "Master JS"]
6 
7// 2. pop() - Removes and returns the LAST element
8const removedLast = tasks.pop();
9console.log(removedLast); // "Master JS"
10 
11// 3. unshift() - Adds one or more elements to the BEGINNING
12tasks.unshift("Morning Yoga");
13console.log(tasks); // ["Morning Yoga", "Study HTML", "Learn CSS"]
14 
15// 4. shift() - Removes and returns the FIRST element
16const removedFirst = tasks.shift();
17console.log(removedFirst); // "Morning Yoga"

3. Searching in Arrays

A. .includes()

Checks if an item exists; returns true or false:

1const colors = ["red", "green", "blue"];
2console.log(colors.includes("green")); // true
3console.log(colors.includes("yellow"));// false

B. .indexOf()

Returns index of item, or -1 if not found:

1console.log(colors.indexOf("blue")); // 2
2console.log(colors.indexOf("purple")); // -1

4. Subarrays: .slice() vs. .splice() (Crucial Difference!)

MethodMutates Original Array?Purpose
.slice(start, end)NO (Pure)Extracts a shallow copy of a portion of the array
.splice(start, deleteCount, ...items)YES (Mutates)Deletes, replaces, or inserts items in place!
1const letters = ["A", "B", "C", "D", "E"];
2 
3// .slice does NOT change original:
4const sub = letters.slice(1, 4);
5console.log(sub); // ["B", "C", "D"]
6console.log(letters); // ["A", "B", "C", "D", "E"] (Intact!)
7 
8// .splice DELETES items from original:
9// Remove 2 items starting from index 1, and insert "X":
10letters.splice(1, 2, "X");
11console.log(letters); // ["A", "X", "D", "E"] (Mutated!)

5. Joining Arrays into Strings: .join()

1const breadcrumbs = ["Home", "Courses", "JavaScript"];
2console.log(breadcrumbs.join(" > ")); // "Home > Courses > JavaScript"

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
What does arr.push("item") do?
Question 2
What does arr.shift() do?
Question 3
What is the fundamental difference between arr.slice() and arr.splice()?
Question 4
If const arr = ["A", "B", "C"], what does arr.indexOf("D") return?
Question 5
How do you concatenate all elements of ["2026", "09", "15"] with hyphens into a string "2026-09-15"?
Next Lesson

Object Basics and Properties

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Arrow Functions (Basic)Object Basics and Properties

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

Mentor-Led Practical Training

Master JavaScript for Beginners with Hands-On Projects

Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext