![]() Index: This denotes the current index for which the function is called.currentValue: This denotes the value present at the current index in the array.In case no such element is present in the array that satisfies the specified condition.įunction specified is called using three arguments:.Array specified in the argument has no elements, that is, if it is an empty array.In case any of the below 2 conditions is true, -1 is returned instead of any index value. In this complete work, elements of the array remain unchanged. Once such an element is discovered in the array, the position of the element in the array is returned by the function. It is executed until a value is found that returns true for the specified condition. The findIndex() method executes the function specified in the argument for each and every index value of the array. ![]() How findIndex() Method Works in JavaScript? I'm also naming them property and value, since that's the usual name for such things (or key and value).Note: Here, the original values of the array being referred to the remain unchanged. If you want to make it clear that all the parts are required, then just use regular arguments: function findIndexInData(data, property, value) Why are you using an object to pass the arguments? You need all three components ( data, where, and what), whereas a object usually means each part is optional. ![]() But I'd like to comment on your current code: Eric Blade is correct that this is a perfect use-case for findIndex.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |