diff --git a/core/engine/src/object/builtins/jstypedarray.rs b/core/engine/src/object/builtins/jstypedarray.rs index 99d533d6ccb..4fee5d5f09c 100644 --- a/core/engine/src/object/builtins/jstypedarray.rs +++ b/core/engine/src/object/builtins/jstypedarray.rs @@ -358,7 +358,42 @@ impl JsTypedArray { ) } - /// Calls `TypedArray.prototype.findIndex()`. + /// The `find_index` method of Array instances returns the index of the first + /// element in an array that satisfies the provided testing function. + /// If no elements satisfy the testing function, None is returned. + /// + /// It calls `TypedArray.prototype.findIndex()`. + /// + /// # Examples + /// + /// ``` + /// # use boa_engine::{JsResult, object::{builtins::JsUint8Array, FunctionObjectBuilder}, NativeFunction, JsValue, Context}; + /// # fn main() -> JsResult<()> { + /// let context = &mut Context::default(); + /// let data: Vec = (0..=255).collect(); + /// let array = JsUint8Array::from_iter(data, context)?; + /// + /// let greter_than_10_predicate = FunctionObjectBuilder::new( + /// context.realm(), + /// NativeFunction::from_fn_ptr(|_this, args, _context| { + /// let element = args + /// .first() + /// .cloned() + /// .unwrap_or_default() + /// .as_number() + /// .expect("error at number conversion"); + /// Ok(JsValue::Boolean(element > 10.0)) + /// }), + /// ) + /// .build(); + /// assert_eq!( + /// array.find_index(greter_than_10_predicate, None, context), + /// Ok(Some(11)) + /// ); + /// + /// # Ok(()) + /// # } + /// ``` #[inline] pub fn find_index( &self,