To use the indexOf
function from lodash in JavaScript, follow these steps:
Install lodash by running npm install lodash
command in your terminal.
Import lodash
in your JavaScript file using the require
statement:
index.tsx29 chars2 lines
indexOf
function:index.tsx29 chars2 lines
indexOf
function from lodash to get the index of the element you are searching for:index.tsx33 chars2 lines
In this example, the indexOf
function will return the index of the number 3
in the arr
array. The resulting value of index
will be 2
since 3
is located at the 2nd index in the arr
array.
Here's the full code block:
index.tsx124 chars5 lines
gistlibby LogSnag