Let some string consisting of digits be given:
let str = '12345';
Let's check if the first character of this
string is equal to the number 1
:
let str = '12345';
if (str[0] == 1) {
console.log('!');
}
Let's now check the last character for
equality to the number 5
:
let str = '12345';
let last = str[str.length - 1];
if (last == 5) {
console.log('!');
}
Given a variable containing some string.
Check that this string starts with
character 'a'
.
Given a variable containing some string.
Check that this string ends with
the character 'x'
.
Given a variable containing some string.
Check that this string starts with
the character 'a'
or the
character 'b'
.