Zara  Bryant

Zara Bryant


Simplify Your JavaScript with .some() and .find()

Originally published by Etienne Talbot at

I thought I should share two more array methods that are useful tools in a JavaScript developer’s arsenal: .some() and .find().

Let’s dive!

.some() JavaScript

This array method helps you determine if one or more of its values correspond to something you’re looking for. If that doesn’t sound clear to you, let me illustrate with an example…

Here’s a list of operatives working for your super secret organization:

var operatives = [
  { id: 12, name: 'Baze Malbus', pilot: false },
  { id: 44, name: 'Bodhi Rook', pilot: true },
  { id: 59, name: 'Chirrut Îmwe', pilot: false },
  { id: 122, name: 'Jyn Erso', pilot: false }

You want to know if there are any pilots among your operatives. There are many ways to achieve that goal. Most people will probably use .forEach() and do something like this:

var listHasPilots = false;operatives.forEach(function (operative) {
  if (operative.pilot) {
    listHasPilots = true;

That’s a lot of lines just to see if the list contains a pilot. Let’s try using .some()!

var listHasPilots = operatives.some(function (operative) {
  return operative.pilot;

We can even be more concise with arrow functions (requires ES6 support, Babel or TypeScript)

const listHasPilots = operatives.some(operative => operative.pilot);

How does it work?

Well, you pass .some() a function as the argument. That function runs for each value in the array. You can then see if the value fits the condition you’ve written. The function must return a boolean (although a truthy/falsy value works as well). As soon as one true is returned, .some() will itself return true. If none of the values, when processed in your condition, return true (if they all return false), then .some() will return false.

Note that as soon as a single true is returned, .some() will stop checking the other array values. In our example above, the function only runs twice as the second operative, Bodhi Rook, is a pilot. No need to check for other pilots.

TL;DR : if some of your array values correspond to what you’re looking for, .some() will return true. If not, it’ll return false.

.every() JavaScript

As was pointed out in the comments, know that you can also check if every value of the array matches your condition by using .every() . It works exactly like .some(), but will return true only if every occurence match.

.find() JavaScript

This array method does exactly what it says: it finds what you’re looking for. In a nutshell, .find() will return the first value that corresponds to the passed condition. Let’s see it in action with the same data as earlier.

Here is our list of operatives:

var operatives = [
  { id: 12, name: 'Baze Malbus', pilot: false },
  { id: 44, name: 'Bodhi Rook', pilot: true },
  { id: 59, name: 'Chirrut Îmwe', pilot: false },
  { id: 122, name: 'Jyn Erso', pilot: false }

It’s the same as before, except this time instead of asking ourselves if we have a pilot in our ranks, we want the profile of that pilot! Let’s output the value we need using .find() :

var firstPilot = operatives.find(function (operative) {
  return operative.pilot;

Even shorter with ES6’s arrow functions:

const firstPilot = operatives.find(operative => operative.pilot);

As you can see the code is exactly the same as with .some() , the only difference is that we changed some for find ! But now, instead of returning a boolean, it will return the first pilot in our list.

Let me emphasize: .find() will return the first match. If more values match your condition, it won’t matter. Only the first match will be returned. If you need a list of all matches, then you should use .filter() instead of .find() .

If no match is found, .find() will return undefined .


Using .find() and .some() instead of common loops like .for or .forEach() not only makes your code shorter, but also makes your intent clearer. A loop could be used to do anything, but using .find() states that you are looking for one particular array item. As for .some() , you are clearly checking if the array contains items that fit your needs or not.

Make your code clearer! Use .find() and .some() when relevant.

That’s it!

Hopefully you’ve learned something new. Share the knowledge with your fellow developers!

Do you know of more JavaScript gems that could help the JS community write cleaner, simpler code? If so, leave a comment and I will try to write a blog post about it.

Keep coding!

Thanks for reading

If you liked this post, please do share/like it with all of your programming buddies!

Follow us on Facebook | Twitter

Further reading

JavaScript Programming Tutorial - Full JavaScript Course for Beginners

Top 10 JavaScript array methods you should know

New ES2019 Features Every JavaScript Developer Should Know

Best JavaScript Frameworks, Libraries and Tools to Use in 2019

JavaScript Basics Before You Learn React

#javascript #web-development

What is GEEK

Buddha Community

Simplify Your JavaScript with .some() and .find()
Coy  Roberts

Coy Roberts


Javascript array find: How to Find Element in Javascript

Javascript array find() is an inbuilt js function that returns the value of the first item in the Array that satisfies a provided testing function. Otherwise,  undefined will be returned. The array find() method returns the value of the first element in an array that passes a test of provided function.

If an Array find() method finds an item where the function returns a true value. Javascript find() returns the value of that array item immediately and does not check the remaining values of that Array.

Javascript array find

Javascript Array.find() is the inbuilt function that is used to get a value of the first item in the Array that meets the provided condition. If you need an index of the found item in the Array, use the  findIndex(). If you need to find an index of the value, use Array  .prototype.indexOf(). If you need to find if the value exists in an array, use Array  .prototype.includes().

It checks all the items of the Array, and whichever the first item meets, the condition is going to print. If more than one item meets the condition, then the first item satisfying the requirement is returned. Suppose that you want to find the first odd number in the Array. The argument function checks whether an argument passed to it is an odd number or not.

Javascript find() function calls an argument function for every item of the Array.  The first odd number for which argument function returns true is reported by the find() function as the answer.

#javascript #javascript find #array.find

Rahul Jangid


What is JavaScript - Stackfindover - Blog

Who invented JavaScript, how it works, as we have given information about Programming language in our previous article ( What is PHP ), but today we will talk about what is JavaScript, why JavaScript is used The Answers to all such questions and much other information about JavaScript, you are going to get here today. Hope this information will work for you.

Who invented JavaScript?

JavaScript language was invented by Brendan Eich in 1995. JavaScript is inspired by Java Programming Language. The first name of JavaScript was Mocha which was named by Marc Andreessen, Marc Andreessen is the founder of Netscape and in the same year Mocha was renamed LiveScript, and later in December 1995, it was renamed JavaScript which is still in trend.

What is JavaScript?

JavaScript is a client-side scripting language used with HTML (Hypertext Markup Language). JavaScript is an Interpreted / Oriented language called JS in programming language JavaScript code can be run on any normal web browser. To run the code of JavaScript, we have to enable JavaScript of Web Browser. But some web browsers already have JavaScript enabled.

Today almost all websites are using it as web technology, mind is that there is maximum scope in JavaScript in the coming time, so if you want to become a programmer, then you can be very beneficial to learn JavaScript.

JavaScript Hello World Program

In JavaScript, ‘document.write‘ is used to represent a string on a browser.

<script type="text/javascript">
	document.write("Hello World!");

How to comment JavaScript code?

  • For single line comment in JavaScript we have to use // (double slashes)
  • For multiple line comments we have to use / * – – * /
<script type="text/javascript">

//single line comment

/* document.write("Hello"); */


Advantages and Disadvantages of JavaScript

#javascript #javascript code #javascript hello world #what is javascript #who invented javascript

Hire Dedicated JavaScript Developers -Hire JavaScript Developers

It is said that a digital resource a business has must be interactive in nature, so the website or the business app should be interactive. How do you make the app interactive? With the use of JavaScript.

Does your business need an interactive website or app?

Hire Dedicated JavaScript Developer from WebClues Infotech as the developer we offer is highly skilled and expert in what they do. Our developers are collaborative in nature and work with complete transparency with the customers.

The technology used to develop the overall app by the developers from WebClues Infotech is at par with the latest available technology.

Get your business app with JavaScript

For more inquiry click here

Book Free Interview:

#hire dedicated javascript developers #hire javascript developers #top javascript developers for hire #hire javascript developer #hire a freelancer for javascript developer #hire the best javascript developers

Niraj Kafle


The essential JavaScript concepts that you should understand

As a JavaScript developer of any level, you need to understand its foundational concepts and some of the new ideas that help us developing code. In this article, we are going to review 16 basic concepts. So without further ado, let’s get to it.

#javascript-interview #javascript-development #javascript-fundamental #javascript #javascript-tips

Ajay Kapoor


JS Development Company India | JavaScript Development Services

PixelCrayons: Our JavaScript web development service offers you a feature-packed & dynamic web application that effectively caters to your business challenges and provide you the best RoI. Our JavaScript web development company works on all major frameworks & libraries like Angular, React, Nodejs, Vue.js, to name a few.

With 15+ years of domain expertise, we have successfully delivered 13800+ projects and have successfully garnered 6800+ happy customers with 97%+ client retention rate.

Looking for professional JavaScript web app development services? We provide custom JavaScript development services applying latest version frameworks and libraries to propel businesses to the next level. Our well-defined and manageable JS development processes are balanced between cost, time and quality along with clear communication.

Our JavaScript development companies offers you strict NDA, 100% money back guarantee and agile/DevOps approach.

#javascript development company #javascript development services #javascript web development #javascript development #javascript web development services #javascript web development company