Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

indexof vs findindex

/* findIndex vs indexOf methods.
All return -1 when no value is found. */

let myArray = [9, 2, 2, 8, 4, 2, 5, 6, 2, 9];

// findIndex(arg => argCondition): return the first index 
// for which the given function is true.
myArray.findIndex(x => x > 2); // → 3

// indexOf(value): return the value's first index.
myArray.indexOf(2); // → 1

// lastIndexOf(value): return the value's last index.
myArray.lastIndexOf(2); // → 8

// indexOf(value, start): return the value's first index, 
// starting at the given position.
myArray.indexOf(2, 3); // → 5

// lastIndexOf(value, stop): return the value's last index, 
// stopping at the given position.
myArray.lastIndexOf(2, 3); // → 2
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript newline in alert 
Javascript :: ... unicode 
Javascript :: react multiple event handlers] 
Javascript :: mongoose check if string is objectid 
Javascript :: how to show day name in javascript using array 
Javascript :: ReferenceError: Buffer is not defined 
Javascript :: javascript json parse 
Javascript :: proactive vs reactive 
Javascript :: javascript line through 
Javascript :: push input value to array javascript 
Javascript :: react onclick function 
Javascript :: can filter be used on objects in javascript 
Javascript :: object exists in array javascript 
Javascript :: how to send header in axios 
Javascript :: js invert color 
Javascript :: how to get value in formgroup in angular 
Javascript :: where to place async in const function 
Javascript :: find array with children javascript 
Javascript :: discord bot playing game 
Javascript :: tabuada js 
Javascript :: addclass jquery 
Javascript :: axios get status code 
Javascript :: how to upload file in material ui 
Javascript :: how get first option in select in vue js 
Javascript :: npm uniqueid 
Javascript :: check if an object contains a value in javascript 
Javascript :: get current time epoch javascript 
Javascript :: plotly js y axis range 
Javascript :: javascript check less width of window 
Javascript :: how to convert string to lowercase in javascript 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =