Reputation: 693
I'm trying to get the last word from the string:
var str = "Member/GetRefills";
var param = str.split(" ").pop();
console.log(param);
Expected result:
GetRefills
Upvotes: 1
Views: 202
Reputation: 1791
Do this instead:
var param = str.split('/');
var paramLast = param[param.length - 1];
pop() is not always a good practice. pop() removes the last element of an array which in some cases might cause problems.
param[param.length - 1]
does the same job as pop() but more safely.
Upvotes: 0
Reputation: 27285
Try splitting on "/"
instead.
const str = "Member/GetRefills";
const param = str.split("/").pop();
Upvotes: 7