我正在尝试检查字符串是否包含字符串中的特定给定句子。我有下面的字符串,因为我想检查'already registered'句子是否存在但是字符串包含数组所以我无法得到。message = 'User error fabric-ca request register failed with errors [[{"code":0,"message":"Registration of \'yandgsub15\' failed: Identity \'yandgsub15\' is already registered"}]]' }我尝试了以下功能,但是我无法获得它。请问有人有解决办法吗?var n = error.includes("registered");
2 回答
料青山看我应如是
TA贡献1772条经验 获得超8个赞
您正在尝试在名为 error 的字符串中搜索“registered”,但没有尝试这样做:
message = 'User error fabric-ca request register failed with errors [[{"code":0,"message":"Registration of \'yandgsub15\' failed: Identity \'yandgsub15\' is already registered"}]]' }
var n = message.includes("registered");
呼如林
TA贡献1798条经验 获得超3个赞
我认为您只是不搜索好的变量
在您的示例中,您正在尝试搜索"registered"而error不是message
下面的代码正在工作
message = 'User error fabric-ca request register failed with errors [[{"code":0,"message":"Registration of \'yandgsub15\' failed: Identity \'yandgsub15\' is already registered"}]]'
var n = message.includes('registered')
console.log(n) // true
添加回答
举报
0/150
提交
取消