Skip to content

Conversation

@serhatece
Copy link

No description provided.

@serhatece
Copy link
Author

update

* - Use the find() method to find a specific item in the array
* - Remove the item you found using the find method from the array.
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// Step 1: Build an array with 8 items
let items = ["apple", "banana", "cherry", "date", "elderberry", "fig", "grape", "honeydew"];
console.log("Initial array:", items);

// Step 2: Remove the last item
let lastItem = items.pop();
console.log("Array after removing last item:", items);
console.log("Last item:", lastItem);

// Step 3: Add the last item as the first item on the array
items.unshift(lastItem);
console.log("Array after adding last item to the start:", items);

// Step 4: Sort the items by alphabetical order
items.sort();
console.log("Array sorted alphabetically:", items);

// Step 5: Use the find() method to find a specific item in the array
let itemToFind = "cherry";
let foundItem = items.find(item => item === itemToFind);
console.log("Found item:", foundItem);

// Step 6: Remove the item you found using the find() method from the array
if (foundItem) {
items = items.filter(item => item !== foundItem);
console.log(Array after removing ${foundItem}:, items);
} else {
console.log(${itemToFind} not found in the array.);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants