Skip to main content

Command Palette

Search for a command to run...

Learn Array Methods Easily with Barcelona's Approach

Updated
3 min read
Learn Array Methods Easily with Barcelona's Approach
H
i write stuff

Welcome to the Blog, it’s a fun and hands-on way to learn Array methods in JavaScript.

So SIT BACK, RELAX, and enjoy the show

AND TO MAKE IT EVEN MORE WE HAVE …DRUMROLLLSSS….

BARCELONA🎉🎉🎉

So here’s the squad of Barcelona 2025-26 Season

let team = new Array("Joan Garcia","Jules Koundé","Pau Cubarsí","Gerard Martín","Alejandro Balde"," Frenkie de Jong","Pedri","Fermín López","Lamine Yamal","Raphinha","Lewandowski",);

// The above code represent the array of Barca 11 , 2025-26 season

YOU ARE APPOINTED AS THE NEW MANAGER OF BARCELONA, AND YOU HAVE TO ACHIEVE 10 OBJECTIVES TO MAKE THE CLUB BETTER

OBJECTIVE #1 - TALK WITH Robert Lewandowski.

let team = new Array("Joan Garcia","Jules Koundé","Pau Cubarsí","Gerard Martín","Alejandro Balde"," Frenkie de Jong","Pedri","Fermín López","Lamine Yamal","Raphinha","Lewandowski",);

// The above code represent the array of Barca 11 , 2025-26 season
console.log(team.include("Lewandowski");

The include() method is used to find whether the array includes a certain value and return a Boolean value


OBJECTIVE #2 - DUE TO Robert Lewandowski's Age, YOU HAVE TO REMOVE HIM FROM THE Squad

let team = new Array("Joan Garcia","Jules Koundé","Pau Cubarsí","Gerard Martín","Alejandro Balde"," Frenkie de Jong","Pedri","Fermín López","Lamine Yamal","Raphinha","Lewandowski",);

// The above code represent the array of Barca 11 , 2025-26 season
console.log(team.pop())
//removing and returning last element(player)
console.log(team)
// the squad after removing Lewandowski


OBJECTIVE #3 - PROMOTE 2 LA MASIA GRADUATES INTO THE FIRST TEAM

let team = new Array("Joan Garcia","Jules Koundé","Pau Cubarsí","Gerard Martín","Alejandro Balde"," Frenkie de Jong","Pedri","Fermín López","Lamine Yamal","Raphinha","Lewandowski",);
// The above code represent the array of Barca 11 , 2025-26 season
let UpdatedSquad = team.push("Dro","Toni");
//2 LA MASIA GRADUATES(NEW VALUES TO ADD IN ARRAY)
console.log(team);

So the Push method is like Repairo(Harry Potter reference), it will fix all your problems related to the squad as the Manager, as you can add any value/Variable(Player) in the array(squad)


OBJECTIVE #4 - TALK WITH Gerard Martín and Alejandro Balde about the team's defensive action, but don’t inform other players

let team = new Array("Joan Garcia","Jules Koundé","Pau Cubarsí","Gerard Martín","Alejandro Balde","Frenkie de Jong","Pedri","Fermín López","Lamine Yamal","Raphinha","Lewandowski",);
// The above code represent the array of Barca 11 , 2025-26 season
console.log(team.slice(3,5))

The slice Method in JavaScript takes 2 parameters (Start, End) and returns the values that are between the given parameters

In this case, Gerard Martín and Alejandro Balde are in 4th and 5th place, respectively, so we took ( 3,5) as (Start, End) Parameters


OBJECTIVE #5 - SIGN RASHFORD FROM MAN UTD ON A LOAN DEAL TO MAKE THE SQUAD STRONGER

let team = new Array("Joan Garcia","Jules Koundé","Pau Cubarsí","Gerard Martín","Alejandro Balde","Frenkie de Jong","Pedri","Fermín López","Lamine Yamal","Raphinha","Lewandowski",);
// The above code represent the array of Barca 11 , 2025-26 season
let ManUtd = new Array("rashford", "garnacho", "bruno fernandez", "sesko");

//Taking rashford on Loan from Man UTD
team.unshift(ManUtd[0]);

console.log(team);

The unshift() method of Array instances adds the specified elements to the beginning of an array and returns the new length of the array.


I will add More Objectives in the near future so you can refer to the MDN documentation

till then PEACE 🕊️✌️