Underscore.JS - metodo lastIndexOf

Sintassi

_.lastIndexOf(array, value, [fromIndex])

Il metodo lastIndexOf restituisce l'indice del valore in array. Se viene passato fromIndex, la ricerca inizierà daIndex in array.

Esempio

var _ = require('underscore');

var list = [1, 2, 3, 4, 5, 6, 3, 4]
//Example: get last index of 3
result = _.lastIndexOf(list, 3);
console.log(result)

//Example: get last index of 3 starting from 4th index
result = _.lastIndexOf(list, 3, 4 );
console.log(result)

Salvare il programma sopra in formato tester.js. Eseguire il comando seguente per eseguire questo programma.

Comando

\>node tester.js

Produzione

6
2