I have an array that contains three different strings for example:
[ 'obtain wealth1', 'obtain dreams3', 'obtain discretion3' ]
The array is created from a function I’ve written.
What I want to do next is compare the last characters of the strings to one another (the numbers) to see if I produce a match.
How would I go about doing this?
Thanks for the help.
First loop through the array and determine (with an if statement) if the elements held at the positions in the array have, as its last character, a value equal to the number you wish. You can add else if statements to check for
multiple conditions. We use the slice method with an argument of -1 to check for the rightmost character in the string.