I am working on some suitable way of sorting an array on the basis of search string. For example here is an array
var myarray = ["2386", "1234", "3867"];
and here is the string which I want to search in the above array
var searchkey = 123;
Upon sorting on the basis of search string, the result should be like this
var filtered_array= ["1234", "2386", "3867"];
What I want is
for(var i = 0; i < myarray.length; i++) {
if (myarray[i].indexOf(searchkey) > 1)
{
filtered_array.push(myarray[i]);
}else{
unfiltered_array.push(myarray[i]);
}
}
Waiting for valuable suggestions!
searchkeynot be a string as well?