Q:

get a most appropriately matching string from an array

Suppose, I've a string - "abcfile.csv" & an array of strings - 

["abc.csv", "abcf.csv", "cde.doc", "abcdefile.csv", "abcfi.csv"]
Here, I want to partially match given string "abcfile.csv" with the array of strings and It should give me an element from array as an output in which the most no. of consecutive characters are matching.. 

That is, in this example, It should return "abcfi.csv" from the array as it has the more no. of matching consecutive characters with "abcfile.csv".

I tried with some string equality methods but it doesn't help. (includes, === etc).

Update:

I'm trying to apply the solution given by @Alexandru-Ionut Mihai on my actual data, but mess up with some cases - 

let arrayFiles = ["Account_Summary_(LS)_Mar'17.csv", "Additions and Changes_MACD (LS)_Mar'17.csv", "Adjustment and Payments_Mar'17.csv", "CDR LD.csv", "CDR's_-_All_(LS)_Mar'17.csv", "CSR.csv", "Customer_Service_Records_(LS)_Mar'17.csv", "Discounts, Promotions and Fees (LS)_Mar'17.csv", "Equipment Other Charges (LD)_Mar'17.csv", "Inventory Circuits (LD)_Mar'17.csv", "Local Usage Detail (LS)_Mar'17.csv", "Other_Carrier_Detail_(LS)_Mar'17.csv", "Service Summary (LD)_Mar'17.csv", "Tax Detail (LD)_Mar'17.csv", "Tax_Detail_(LS)_Mar'17.csv"];

let arrayTable = ["CSR.csv", "Tax Detail LD.csv", "Tax Detail LS.csv", "Additions and Changes MACD LS.csv", "Adjustment and Payments.csv", "CDR LS.csv", "CDR LD.csv", "Discounts Promotions and Fees LS.csv", "Equipment Other Charges LD.csv", "Inventory Circuits LD.csv", "Local Usage Detail LS.csv", "Other Carrier Detail LS.csv", "Audio Conference.csv", "Toll Free.csv", "Other Charges.csv", "Account Statement.pdf", "Extended Area service.csv", "Local Message Services.csv", "Report - Charges by Line taxes.csv", "Billing Adjustments.csv", "Usage Details.csv", "Account Statement.pdf"];

let string = arrayFiles[11];    // "Other_Carrier_Detail_(LS)_Mar'17.csv"

let found;
while (string.length > 0) {
    let elem = arrayTable.find(a => a.includes(string));
    if (elem) {
        found = elem;
        break;
    }
    string = string.slice(0, -1);
}
console.log(found);

Here, I expect it to return arrayTable[12] i.e. "Other Carrier Detail LS.csv", but it is returning "Equipment Other Charges LD.csv"

A:

You should use a while loop and check if exists array items which contains the desired string.
After every iteration you should slice the string without last char and so on..
abcfile.csv -> abcfile.cs -> abcfile.c -> abcfile. -> abcfile -> abcfil -> abcfi -> abcf -> abc -> ab -> a ->""
With this method you will find out the most appropriately matching string from an array.

let string = "abcfile.csv";
let array = ["abc.csv", "abcf.csv", "cde.doc", "abcdefile.csv", "abcfi.csv"];
let found;
while(string.length > 0){
  let elem = array.find(a => a.includes(string));
  if(elem){
    found = elem;
    break;
  }
  string = string.slice(0,-1);
}
console.log(found);

