I have some webhook and the return response is
message: 'uat.chatbot: Klhhn'
message: 'Zulkifli Raihan: Hello'
The Example :
message: 'name from sender: The Message'
How can i get The Message in javascript?
CodePudding user response:
You can use a regex. I assumed that your:
message: 'Zulkifli Raihan: Hello'
was actually a property on an object, but the regex below can be modified if the whole thing was a string too.
const data = {
message: 'Zulkifli Raihan: Hello'
};
const matches = data.message.match(/:\s*([^:] )$/);
console.log(matches[1]);
CodePudding user response:
message.split(":").slice(-1).join("").trim()
CodePudding user response:
Using simple string manipulation:
var response = "message: 'name from sender: The Message'";
var msg = response.split(": ")[2].slice(0,-1);
console.log(msg)