Lesson 2
Arrays & Methods
Advanced array operations
1What is an Array?✨
An array is a special type of variable that can hold multiple values at once. It's like a box that can store a collection of items, all of the same type. Arrays make it easier to organize and manipulate data in JavaScript.
2Why Learn Arrays?🎯
- ✓ Store multiple values in a single variable
- ✓ Perform operations on collections of data
- ✓ Simplifies code for loops and iterations
- ✓ Essential for working with data in web applications
3Creating an Array💡
You can create an array using square brackets. Here's how to declare an array:
const fruits = ['Apple', 'Banana', 'Cherry'];This creates an array named fruits that contains three items.
4Accessing Array Elements🚀
You can access elements in an array using their index, which starts at 0. For example:
console.log(fruits[0]); // Output: AppleThis shows the first item in the fruits array.
5Common Array Methods🔍
JavaScript provides many built-in methods to manipulate arrays. Some useful ones include:
- push(): Adds an item to the end of the array
- pop(): Removes the last item from the array
- shift(): Removes the first item from the array
- unshift(): Adds an item to the beginning of the array6Example of using push and pop:⭐
fruits.push('Orange');
console.log(fruits); // Output: ['Apple', 'Banana', 'Cherry', 'Orange']
fruits.pop();
console.log(fruits); // Output: ['Apple', 'Banana', 'Cherry']7Looping Through Arrays🧩
You can use loops to iterate through arrays. The forEach() method is a great way to run a function on each item:fruits.forEach(function(fruit) {
console.log(fruit);
});8// Output:🎈
- // Apple
- // Banana
- // Cherry
9What You'll Build This Grade✨
- ✓ Interactive applications using arrays
- ✓ Simple games that require item storage
- ✓ Dynamic lists and data management tools
- ✓ Fun projects that showcase your creativity
🎯 Practice Challenges
Master Arrays & Methods by completing all 3 difficulty levels
Arrays & Methods - Easy Challenge
Start with the basics. Perfect for beginners!
Arrays & Methods - Medium Challenge
Get more challenging. Build your confidence!
Arrays & Methods - Hard Challenge
Master this concept. Prove your skills!
🏆 Study a lesson for 2+ minutes to earn +10 TalentJR Points a day. Badges, certificates & prizes →
Ready to Master Arrays & Methods? 🚀
Complete the challenges, take the quiz and keep your learning streak going!
Keep learning
- ← Previous lessonLesson 1: Objects & ClassesObject-oriented JavaScript
- Next lesson →Lesson 3: Async & PromisesHandle asynchronous code
- Grade 10 courseC Programming - System ProgrammingC coding course for kids.
- Student ToolsFree calculators for studentsPercentage, fraction, ratio and marks calculators with steps.
- CBSEClass 9 CBSE & NCERT study materialMaths, Science and Computer chapters with solutions.
- Future SkillsExplore future skillsAI, robotics and new-age skills explained for students.