Here is an array of objects of some popular space friends with some of their attributes:
const characters = [
name: 'Luke Skywalker',
name: 'Darth Vader',
name: 'Leia Organa',
name: 'Anakin Skywalker',
With the .every() method we are going to check if every character has a mass of under 200.
const shorterThan200 = characters.every( character => character.height < 200)console.log(shorterThan200)
Printing the return value of shorterThan200 will result in either a true or false boolean statement. In this case, it returns false because Darth Vader worked out legs yesterday and is barely making it over 200. Gains!
In this next scenario, we will use the .some() method to check and see wether any of the characters blue eyes.
const anyBlueEyes = characters.some(character => character.eye_color === 'blue)console.log(anyBlueEyes)
Printing the return statement of anyBlueEyes here will give us a true statement. It looks like Anakin passed on his eye color down to his kin.
Hope you learned a bit about some methods that can help you save some lines of code in the future!