I have a problem in obtaining the index, if in an array there are some similar words but with a different index position and when I select one of the word, the index that I get is not from words but from which I select the same word in previous position
for example I have a sentence:
The Harvest is the process of gathering
the bold word is the word that I choose..
this is my code:
var str = "The Harvest is the process of gathering";
var myArray = str.split ("");
var Select = "the";
and I have a function like this:
function getIndex (arrayItem, item) {
for (var x = 0; x <arrayItem.length; x + +) {
if (arrayItem [x] == item) {
return x;
}
}
return -1;
}
var idx = getIndex (myArray, Select);
how to get that index?