Reputation: 13
What is the JavaScript statement that would be used to determine the position of the first slash / within the string variable "address" and assign that value to the "result" variable.
Upvotes: 1
Views: 108
Reputation: 1516
The method indexOf() returns the first occurrence of a given value within the string object. It returns -1 if the value isn't found.
var result = address.indexOf('/');
Upvotes: 1
Reputation: 26930
This will tell index of first '/':
var a = 'asdasd/';
a.indexOf('/');
And this will tell last:
var a = 'asdasd/asfwerf/';
a.lastIndexOf('/');
Upvotes: 1