Tech Junkie Blog - Real World Tutorials, Happy Coding!: JavaScript Array Methods: some() Method

Friday, December 31, 2021

JavaScript Array Methods: some() Method

The some() array works similar to the every() method, it also returns true or false when the condition is met.  some() needs to match just one element in the array that meets the condition to return true.  So lets run the same code that we ran for the every() method.  We will test to see if the array is greater than 50 for the first condition, and then we will test to see if the array is greater than 70 for the second condition.  For the every() method the first condition returns true, while the second condition returns false.  Let's see what happens with the some() method.

        var oilPrices = [70.15, 69.50, 71.23, 74.32, 76.99];

        var greaterThanFifty = oilPrices.some(function (value) { return value > 50; });

        var greaterThanSeventy = oilPrices.some(function (value) { return value > 70 });

        console.log("greaterThanFifty: " + greaterThanFifty);
        console.log("greaterThanSeventy: " + greaterThanSeventy);

As you can see both conditions return true because at least one of the element in the array meets the condition.


  1. Most of the institutes are shifting their classes to online mode these days. Now, when you find the positive side of this, there is a huge negative side to this. If it were a theoretical subject, students might be able to finish this easily. But Java is a programming language, and only practical classes can help a student properly earn the subject. Now under such circumstances, if you are looking for Java assignment help, you are not wrong! Students need to have regular classes in order to learn and rule the subject. But with the distant learning process, the whole thing seems very tough for them. Hence, going for Java programming assignment help is the easiest thing they can go for!

  2. This comment has been removed by the author.


Search This Blog