how to get last index in array javascript
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
if (loc_array[loc_array.length - 1] === 'index.html') {
// do something
} else {
// something else
}console.log(2)
Also in JavaScript:
- stop a video jquery
- node js TypeError [ERR_INVALID_ARG_TYPE]: The argument must be of type string. Received undefined
- what is ajax
- javascript remove all event listeners
- javascript version of sleep
- js random hex color
- javascript object first key
- what is Vanilla JavaScript
- javascript how-do-i-remove-a-property-from-a-javascript-object
- Merging Or Copying Arrays Using Spread Operator
- js switch case
- javascript create 2d array
- bearer token header
- bootstrap show modal jquery
- javascript dom cheat sheet
- javascript array from datalist
- for of mdn
- javascript add color effect
- javascript jqgrid events afterShowForm
- adonis attach
- js get class property
- express hello world
- javascript factorial of a number
- javascript set variable inline