Find
A find operation searches a collection for the first element or entry matching a value or predicate and returns it, or indicates that no match exists.
Secrets of the JavaScript Ninja, Third Edition
A JavaScript method that returns the first array element satisfying a predicate, or undefined if none does.
- How it is used
- Retrieves one array item that satisfies a callback-defined condition.
- How deep it goes
- Demonstrates first-match lookup and an undefined result when no item matches, without implementing the method.
- Examples
- Tests weapon properties on an array of ninja objects, including a successful lookup and a missing match.
- What you can do after
- Apply it via JavaScript's Array.find to retrieve a first match and handle an undefined result.
Read how Secrets of the JavaScript Ninja, Third Edition explains find →
Secrets of the JavaScript Ninja, Second Edition
An Array method that returns the first element passing a callback test, or undefined if none does.
- How it is used
- Finds the first array item that satisfies a callback condition.
- How deep it goes
- Explains callback-based matching and the `undefined` no-match result, without detailing implementation internals.
- Examples
- Finds the ninja wielding a wakizashi and checks for a katana match that yields `undefined`.
- What you can do after
- Apply `find` with a callback to retrieve the first matching array item or detect that none matches.
Read how Secrets of the JavaScript Ninja, Second Edition explains find →
C++ Concurrency in Action, Second Edition
`std::find` is a C++ standard library algorithm that returns the first element in a range equal to a specified value, or the end of the range if none is found.
- How it is used
- Uses early completion to guide the design of parallel search.
- How deep it goes
- Explains early completion and atomic cancellation through a parallel implementation.
- Examples
- Uses an attic photograph search and a four-thread comparison to illustrate early completion.
- What you can do after
- Evaluate when parallel search can lose to serial search and use a flag to signal a found match.
Read how C++ Concurrency in Action, Second Edition explains find →
Clojure: The Essential Reference
find is a Clojure function that searches an associative collection for a key and returns the corresponding key-value entry or nil.
- How it is used
- Searches associative collections when the complete key-value entry, rather than only its value, is needed.
- How deep it goes
- Defines inputs, outputs, supported collections, edge cases, and entry extraction, but does not develop implementation internals.
- Examples
- Demonstrates map entries, vector indexes, subvectors, missing keys, and filtering records with keep.
- What you can do after
- Apply it via Clojure to locate entries, extract keys or values, and retain matching records without exceptions for absent keys.
The Well-Grounded Rubyist, Fourth Edition
find, also known as detect, is an Enumerable method that returns the first element for which its block evaluates truthily, or nil when no element matches.
- How it is used
- Searches an enumerable collection for one matching element using a block-defined selection criterion.
- How deep it goes
- Explains block evaluation, early termination, nil ambiguity, fallback Procs, and contrasts with multi-result selectors.
- Examples
- Uses a numeric array search, a nil-element search, a fallback lambda, and a custom Rainbow enumerable.
- What you can do after
- Apply it to return the first matching element, detect absence through nil, or provide a fallback Proc.
Read how The Well-Grounded Rubyist, Fourth Edition explains find →
Also covered in
- D3.js in Action, Third Edition
- Data-Oriented Programming: Reduce software complexity
- Learn C++ by Example
- Learn Rust in a Month of Lunches
- Kotlin in Action, 2E
- Get Programming with JavaScript Next: New features of ECMAScript 2015, 2016, and beyond
- F# in Action: A Revised Edition of Get Programming with F#
- Grokking Data Structures
What to know first
- arrayAn array is an ordered collection of elements organized in one or more dimensions and accessible by position or index.
- filteringFiltering is the selection or exclusion of data or items according to specified criteria.
- MapA map is an associative data structure that stores key-value associations and supports retrieving values by key.
- setA set is a collection of distinct elements in which membership, rather than order or duplicate occurrences, defines the collection.
Related concepts
- containsalternative to · Contains is a membership-query operation that reports whether a specified value, key, element, or substring occurs in a container or collection.
- get methodalternative to · A lookup operation on a mapping or associative collection that returns the value associated with a key or index, often with a null-like result or supplied default when no entry exists.
- missing valueproduces · A missing value is an expected data value or observation that is absent, unavailable, unknown, or inapplicable.
Questions about find
What is find?
A find operation searches a collection for the first element or entry matching a value or predicate and returns it, or indicates that no match exists.
Which Manning books explain find?
Secrets of the JavaScript Ninja, Third Edition, Secrets of the JavaScript Ninja, Second Edition, C++ Concurrency in Action, Second Edition, Clojure: The Essential Reference and The Well-Grounded Rubyist, Fourth Edition.
What should I know before learning find?
Manning books that teach find usually introduce array, filtering, Map and set first.
What is the difference between find and contains?
A find operation searches a collection for the first element or entry matching a value or predicate and returns it, or indicates that no match exists. Contains is a membership-query operation that reports whether a specified value, key, element, or substring occurs in a container or collection.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.




