Reputation: 1447
I know how to split a value using deliminators. I also know how to slice a value to remove the last couple chars. I need to combine these now, which is the part I can't figure out.
$("#product").val(value.split('|')[0]);
How would I add slice(0,-1)
to this function above? I want it to first split, then slice.
So the result would be everything before the '|' and minus one char
Solved:
$("#product").val(value.split('|')[0].slice(0, -1))
Upvotes: 2
Views: 1832
Reputation: 144679
try this:
var val = value.split('|')[0].slice(0, -1)
$("#product").val(val);
Upvotes: 1
Reputation: 79830
You mean slice the 1st element from array?
Try below,
$("#product").val(value.split('|')[0].slice(0, -1))
Upvotes: 3