Javascript 如何在nodejs中将两个字符串源和目标与fullname进行比较

Javascript 如何在nodejs中将两个字符串源和目标与fullname进行比较,javascript,json,node.js,alexa-voice-service,Javascript,Json,Node.js,Alexa Voice Service,将两个字符串与第三个字符串(如JSON数组全名)进行比较 var source = intentObj.slots.toPlazaName.value.toString(); // Jaipur var destination = intentObj.slots.fromPlazaName.value.toString(); // Kishangarh 匹配此“全名”:“斋浦尔-基桑加尔路段”, 我的回答 { "projectid": 10,

将两个字符串与第三个字符串(如JSON数组全名)进行比较

var source = intentObj.slots.toPlazaName.value.toString(); // Jaipur 
var destination = intentObj.slots.fromPlazaName.value.toString(); // Kishangarh
匹配此
“全名”:“斋浦尔-基桑加尔路段”,

我的回答

{
            "projectid": 10,
            "FullName": "Kishangarh -Ajmer- Beawar",
            "piu": "PIU-Ajmer",
            "NumberofLanes": "6L",
            "NHNo_New": "8",
            "NHNo_Old": "8",
            "Total_Length": 92,
            "state_name": "Rajasthan"
        },
        {
            "projectid": 15,
            "FullName": "Reengus - Sikar",
            "piu": "PIU-Sikar",
            "NumberofLanes": "4L",
            "NHNo_New": "52",
            "NHNo_Old": "11",
            "Total_Length": 44,
            "state_name": "Rajasthan"
        },
        {
            "projectid": 20,
            "FullName": "Rajsamand - Gangapur - Bhilwara",
            "piu": "PIU-Chittorgarh",
            "NumberofLanes": "4L",
            "NHNo_New": "758",
            "NHNo_Old": "76B",
            "Total_Length": 87.25,
            "state_name": "Rajasthan"
        },
我的创建函数

function findSourceDestination(source, destination, callback) {
    var matchPlazas = [];
    var projectFullName = [];

    for (var i = 0; i < nhai_response.GetALexDataInJSONResult.length; i++) {
        // console.log(nhai_response.GetALexDataInJSONResult[i]["FullName"]);
        if (nhai_response.GetALexDataInJSONResult[i]["FullName"].includes(source)) {
            // console.log("source " + nhai_response.GetALexDataInJSONResult[i]["FullName"]);
            projectFullName.push(nhai_response.GetALexDataInJSONResult[i]);
        }
    }

    for (var j = 0; j < projectFullName.length; j++) {
        if (projectFullName[j]["FullName"].includes(destination)) {
            console.log('----------------' +projectFullName[j]["FullName"] + '----------destination '+ destination +'------------');
            matchPlazas.push(projectFullName[j]);
        } 

    }

    callback(matchPlazas);
}
函数findSourceDestination(源、目标、回调){
var matchPlazas=[];
var projectFullName=[];
对于(变量i=0;i
我有另一个全名字符串。我还有两根绳子。我想将源字符串与我的全名匹配第一个单词目标将匹配或包含全名,而不是像源字符串那样的第一个字符串


请帮助我。

如果我很好地理解了您的问题,并且您需要将源代码作为FullName的第一部分,而目标代码则需要位于FullName的其余部分,则此函数可以实现

   // no search in progress, start our search at the end
                     _pos = Length - 1;
                 }
-                else if (!wasLive && String.IsNullOrWhiteSpace(search))
+                else if (!wasLive && string.IsNullOrWhiteSpace(search))
                 {
                     // Handles up up up enter up
                     // Do nothing
 @@ -167,7 +167,7 @@ private string MoveToPrevious(string search)

         private bool SearchDoesntMatch(string search)
         {
-            return !String.IsNullOrWhiteSpace(search) && GetHistoryText(_pos).IndexOf(search) == -1;
+            return !string.IsNullOrWhiteSpace(search) && GetHistoryText(_pos).IndexOf(search) == -1;
         }

         private string GetHistoryMatch(string search)
function findSourceDestination(source, destination, callback) {
    var matchPlazas = [];
    var projectFullName = [];

    for (var i = 0; i < nhai_response.GetALexDataInJSONResult.length; i++) {
        let fullName = nhai_response.GetALexDataInJSONResult[i]["FullName"];
        let fullNameParts = fullName.split("-");
        if (fullNameParts[0].trim().includes(source) && fullName.includes(fullName)) {
            matchPlazas.push(nhai_response.GetALexDataInJSONResult[i]);
        }
    }

    callback(matchPlazas);
}
函数findSourceDestination(源、目标、回调){
var matchPlazas=[];
var projectFullName=[];
对于(变量i=0;i
fullNameParts[0]。trim().includes(源)和&fullName.includes(fullName)不正确