import { List } from 'immutable'; const items = List(['apple', 'banana', 'orange', 'banana']); const index = items.findIndex(item => item === 'banana'); console.log(index); // Output: 1
import { List } from 'immutable'; interface Item { id: number; name: string; } const items: ListIn this example, we create a List containing some items that have an id and a name property. We then use the findIndex method to find the index of an item that has an id of 3. The method returns the index 2, which is the index of the third item in the list. The package library for the immutable List type is called 'immutable'.- = List([ { id: 1, name: 'apple' }, { id: 2, name: 'banana' }, { id: 3, name: 'orange' }, { id: 4, name: 'banana' }, ]); const index = items.findIndex(item => item.id === 3); console.log(index); // Output: 2