I have an array
wich contains multiple same values
["test234", "test9495", "test234", "test93992", "test234"]
Here I want to get the index of every test234
in the array
For that I've tried Array.prototype.indexOf()
method. But It only returns me 0
but I want it to return me [0, 2, 4]
.
How can I do that?
Just make it a for loop to check each array element.
var array = ["test234", "test9495", "test234", "test93992", "test234"];
for (i=0;i<array.length;i++) {
if (array[i] == "test234") {
document.write(i + "<br>");
}
}