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 isFriendFoundUse the built-in method
sort() on friends to sort the names alphabeticallyPrint 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