'Some' method

·

1 min read

  • I recently learned about a new array method called some method that i used in my project.This is the line of code:

  • if (!myReadingList.some(item => item.id === book.id))

  • So this line will check if the book is already in My Reading List array.

    It uses the 'some' method to check if any item in My Reading List has the same id as the book being added.

  • If 'some' returns true, it means the book is already in the list, so the if condition is not met.

  • The exclamation (!)operator at the beginning of the code questions the result of 'some', so the if block executes only if the book is not already in the list.