Just [-1] instead of [.lenght -1]?

Just [-1] instead of [.lenght -1]?
0

#1

Tell us what’s happening:
In order to get the last letter of a string wouldnt be just enough to use [-1]; instead of [some.length -1]?
in python it works with [-1]

Your code so far


// Example
var firstName = "Ada";
var lastLetterOfFirstName = firstName[firstName.length - 1];

// Setup
var lastName = "Lovelace";

// Only change code below this line.
var lastLetterOfLastName = lastName[-1];


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 6.3; Win64; x64; rv:61.0) Gecko/20100101 Firefox/61.0.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/basic-javascript/use-bracket-notation-to-find-the-last-character-in-a-string


#2

You need to use the first method in JavaScript.

This will grab a letter at index -1, which is probably undefined.


#3

This is not Python. However, in JavaScript, you could use a negative index with slice.

var str = 'ABCDEF';
var lastLetterOfStr = str.slice(-1); // "F"