0
0
Javascriptprogramming~15 mins

Why built-in methods are useful in Javascript - See It in Action

Choose your learning style9 modes available
Why built-in methods are useful
πŸ“– Scenario: Imagine you have a list of names of friends you want to invite to a party. You want to quickly check how many friends you have, find if a certain friend is on the list, and sort the names alphabetically.
🎯 Goal: You will create a list of friends and use built-in JavaScript methods to count, check, and sort the names easily.
πŸ“‹ What You'll Learn
Create an array called friends with these exact names: 'Anna', 'Bob', 'Charlie', 'Diana'
Create a variable called friendToFind and set it to 'Bob'
Use the built-in method includes() on friends to check if friendToFind is in the list and store the result in isFriendFound
Use the built-in method sort() on friends to sort the names alphabetically
Print the number of friends, the result of the search, and the sorted list
πŸ’‘ Why This Matters
🌍 Real World
In real life, we often need to manage lists like contacts, tasks, or products. Built-in methods help us quickly search, sort, and count items without extra work.
πŸ’Ό Career
Knowing how to use built-in methods is essential for any programming job because it makes your code efficient and easier to maintain.
Progress0 / 4 steps
1
Create the friends list
Create an array called friends with these exact names: 'Anna', 'Bob', 'Charlie', 'Diana'
Javascript
Need a hint?

Use square brackets [] to create an array and separate names with commas.

2
Set the friend to find
Create a variable called friendToFind and set it to 'Bob'
Javascript
Need a hint?

Use const to create a variable and assign the string 'Bob'.

3
Check if the friend is in the list and sort the list
Use the built-in method includes() on friends to check if friendToFind is in the list and store the result in isFriendFound. Then use the built-in method sort() on friends to sort the names alphabetically.
Javascript
Need a hint?

Use includes() to check presence and sort() to order the array.

4
Print the results
Print the number of friends using friends.length, the value of isFriendFound, and the sorted friends array.
Javascript
Need a hint?

Use console.log() to print each result on its own line.