What is the fastest implementation of the ColdFusion listFindNoCase function in Javascript?

I got spoiled by ColdFusion lists and ran into a situation or two where comma-separated list appears in Javascript. Is there an equivalent listFindNoCase('string','list')or efficient way to implement it in Javascript?

Oh, and he should be able to handle list items with commas, for example: ("Smith, John", "Dow, Jane", "etc.")

What really turns me off.

+5
source share
3 answers

You can use indexOfin conjunction with.toLowerCase()

var list = '"Smith, John" , "Doe, Jane" , "etc..."';
if(list.toLowerCase().indexOf('"Smith, John"'))

, "", "", . , , ( ), :

";Smith, John;Doe, Jane;"

, , , :

";Smith;"

.toLowerCase().indexOf() -1 ( ). ";Smith, John;" 0

+2

FYI: jList: https://github.com/davidwaterston/jList

, " "

listFind : function (list, value, delimiter) {
    delimiter = (typeof delimiter === "undefined") ? "," : delimiter;

    var i,
        arr = list.split(delimiter);

    if (arr.indexOf !== undefined) {
        return arr.indexOf(value) + 1;
    }

    for (i = 0; i < list.length; i += 1) {
        if (arr[i] === value) {
            return i + 1;
        }
    }

    return 0;
},


listFindNoCase : function (list, value, delimiter) {
    delimiter = (typeof delimiter === "undefined") ? "," : delimiter;

    list = list.toUpperCase();
    value = String(value).toUpperCase();

    return this.listFind(list, value, delimiter);
},
+4

, CF char, . "" ", ", ", " - - "", "", "", "". , JS equiv CF listFindNoCase(), listFindNoCase() CF, , CF. , char .

TBH, CF- - ( , ), , : ) ; ) . , , - : - ( CF, JS: CF) ).

, : , .

, JS? - ? : . , ? "" , : CF , . , , , - , - . CSV, .

, (, -, ), (listToArray() CF split() JS). indexOf(), .

sh `ts 'n' , - , - , :

  • indexOf(), , , char, char char . , . , , .
  • indexOf().
  • split() ,
  • list, .

, . .

+3
source

All Articles