简体   繁体   中英

Compare two strings in javascript/jquery

In the string below, I want to split the string separated by "|" (which i can do)and would then like to compare the first part and the boolean part of each such string with the same parts of another string.

var str = "Jacobs21]2]0]Ronan]false|Tom]2]0]Joseph]true|Jacobs21]2]0]NAME$$ALL]false|";
  1. In the string above, Jacobs21]2]0]Ronan]false is one string and so on.
  2. I am more interested in the Jacobs21 part of this string and the boolean value appearing at its end which is "false" here.
  3. Now, I want to compare the first and the last part joined as a single string to form Jocobs21false and similarly, for the another string tomtrue and make a comparison and see if there are any similar matches?
var detailsArray = str.split("|");
var res = [];
for (var i = 0; i < detailsArray.length - 1; i++) {
    finalArray = detailsArray[i].toString().split("]");
    var name = finalArray[0];
    var booleanString = finalArray[4];
    res[i] = name.concat(booleanString);
}
for (var j = 0; j < res.length - 1; j++) {
    if (res[i] == res[i + 1]) {
        //do your stuff
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM