javascript - Search function return multiple results -
i'm trying create search function searches array string , returns index of location in array matches string.
ex:
array: [1,2,3,4,5,2,3,1,6,5,2] search input: 3 output: 2 6 search input: 2 output: 1 5 10
currently have outputting 1 value using
document.getelementbyid("result").innerhtml=
but want homecoming multiple results
if write own function, should able return array of indices:
function indicesof(input, value) { var indices = new array(); (var = 0; < input.length; i++) { if (input[i] == value) indices.push(i); } homecoming indices; }
then can combine array values , set them result location, suggested @anthonygrist:
document.getelementbyid('result').innerhtml = indicesof(input, value).join(', ');
javascript
No comments:
Post a Comment