I have an array
wich contains multiple same values
[\"test234\", \"test9495\", \"test234\", \"test93992\", \"test234\"]
This kind of function doesn't exist built in, but it would be pretty easy to make it yourself. Thankfully, indexOf
can also accept a starting index as the second parameter.
function indexOfAll(array, searchItem) {
var i = array.indexOf(searchItem),
indexes = [];
while (i !== -1) {
indexes.push(i);
i = array.indexOf(searchItem, ++i);
}
return indexes;
}
var array = ["test234", "test9495", "test234", "test93992", "test234"];
document.write(JSON.stringify(indexOfAll(array, "test234")));