Dernière index javascript
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
Grepper
var colors = ["red","blue","green"];
var green = colors[colors.length - 1]; //get last item in the array
const str = "Users/Edit/12345";
let idx = str.lastIndexOf("/"); // returns 10
idx = str.lastIndexOf("x"); // returns -1
idx = str.lastIndexOf("Edit") // returns 6
idx = str.lastIndexOf("edit") // returns -1 -- case sensitive
// add "from" parameter
// the search happens backwards, starting at the provided from parameter
idx = str.lastIndexOf("s"); // returns 4
idx = str.lastIndexOf("s", 3); // returns 1
'canal'.lastIndexOf('a'); // retorna 3
'canal'.lastIndexOf('a', 2); // retorna 1
'canal'.lastIndexOf('a', 0); // retorna -1
'canal'.lastIndexOf('x'); // retorna -1
'canal'.lastIndexOf('c', -5); // retorna 0
'canal'.lastIndexOf('c', 0); // retorna 0
'canal'.lastIndexOf(''); // retorna 5
'canal'.lastIndexOf('', 2); // retorna 2
arr.slice(-1).pop()
const lastElement = arrayName[arrayName.length - 1];
last array index