简体   繁体   English

javascript中这些变量有什么区别

[英]What is the difference between these variables in javascript

A function in my program takes the variable DAT and when I try passing args through it fails.我程序中的一个函数采用变量DAT ,当我尝试通过它传递参数时失败。 I am pretty sure DAT is a JSON and args is array.我很确定DAT是一个 JSON 而 args 是数组。 How would I change args to same variable type as DAT .我如何将 args 更改为与DAT相同的变量类型。

here is my code:这是我的代码:

const args = message.content.match(/\b[^"]+\b|(?!")\S+/g);
const command = args.shift().toLowerCase().slice(prefix.length);


if(command === 'hello'){
    message.channel.send("I only research leave me alone");
    let DAT = ['AAPL', 'PYPL', 'GOOG', 'A'];
    console.log("dat: " + DAT);
    console.log("args: " + args);
    console.log(DAT, args);
}
else if(command === 'research'){

    let DAT = ['AAPL', 'PYPL', 'GOOG', 'A'];
    stockdata.realtime({
        symbols: DAT,
        API_TOKEN: world_token
    })
    .then(response => {
        //console.log(response);
        //console.log("symbol" + response.symbols_returned)

    })
    .catch(error => {
        console.log("error");
    });

}

the result in console结果在控制台

PS C:\Users\gaming pc\bot_code\researchbot> node index.js
ready
dat: AAPL,PYPL,GOOG,A
args: 
[ 'AAPL', 'PYPL', 'GOOG', 'A' ] []
dat: AAPL,PYPL,GOOG,A
args:  AAPL PYPL GOOG A
[ 'AAPL', 'PYPL', 'GOOG', 'A' ] [ ' AAPL PYPL GOOG A' ]

Your regular expression will produce only a single match for your example, ["AAPL PYPL GOOG A"] .您的正则表达式只会为您的示例生成一个匹配项, ["AAPL PYPL GOOG A"] This happens because your regex is non-greedy.发生这种情况是因为您的正则表达式是非贪婪的。 Without knowing exactly what you meant, I won't try to fix your regex;在不知道您的确切意思的情况下,我不会尝试修复您的正则表达式; but /\\S+/ is sufficient to solve the problem you presented here.但是/\\S+/足以解决您在此处提出的问题。

I used an expression from my other bot so I just changed the expression我使用了另一个机器人的表达方式,所以我只是改变了表达方式

const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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