Reputation: 40912
I have a variable set to retrieve the id of a specific element which is "PubRecNum-1" (the number is also variable and will change depending on the record number). What I'm needing is a way to only take the first 3 letters of the variable "Pub" (needed for comparison purposes).
Any ideas?
Upvotes: 0
Views: 678
Reputation: 344595
You can get those letters using substring()
or slice()
:
var str = "PubRecNum-1";
alert(str.substring(0, 3)); // -> "Pub"
alert(str.slice(0, 3)); // -> "Pub"
Upvotes: 3