Reputation: 45
I am trying to check whether string contain specific given sentence in string or not. I have below string in that I want to check 'already registered'
sentence present or not however string is contain array so I couldn't get.
message = 'User error fabric-ca request register failed with errors [[{"code":0,"message":"Registration of \'yandgsub15\' failed: Identity \'yandgsub15\' is already registered"}]]' }
I tried below function, however I couldn't get it though it. please anybody have solution?
var n = error.includes("registered");
Upvotes: 1
Views: 5775
Reputation: 526
You are trying to search for "registered" in a string called error but there isn't try this:
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");
Upvotes: 3
Reputation: 1784
I think you just don't search on the good variable
In your example you're trying to search "registered"
on error
and not on message
The code below is working
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
Upvotes: 2