An Interest In:
Web News this Week
- March 28, 2024
- March 27, 2024
- March 26, 2024
- March 25, 2024
- March 24, 2024
- March 23, 2024
- March 22, 2024
September 11, 2021 03:28 pm GMT
Original Link: https://dev.to/devcronin/level-up-with-javascript-lvl-6-17ff
LEVEL UP with JavaScript! LVL 6
In this blog series tutorial, I will be covering some of the basic JavaScript programming concepts.
This is geared toward beginners and anyone looking to refresh their knowledge.
See the Previous Level Here
Level 6 will cover:
- String Immutability
- Use Bracket Notation to Find the Nth Character in a String
- Use Bracket Notation to Find the Last Character in a String
- Use Bracket Notation to Find the Nth-to-Last Character in a String
String Immutability
Immutable means a string cannot be altered once assigned. The way we make changes to strings is by using methods to change them. We will go over these methods in another tutorial.
// This returns undefined because the string "Lizard" is immutablelet name = "Lizard";name = "Wizard";console.log(name)undefined
Use Bracket Notation to Find the Nth Character in a String
If we want to find which character of a string is sitting at a particular value, we again use bracket notation with the number position we want to find [Nth].
let player = "Druid";console.log(player[2]);"u"
Use Bracket Notation to Find the Last Character in a String
When we want to find the last character of a string, we can subtract one from the string's length.
let spell = "Fireball";spell[spell.length - 1];"l"
Use Bracket Notation to Find the Nth-to-Last Character in a String
Just as we did before to find the Nth and the last character in a string, we can combine the two to find the last to Nth character.
let enemy = "Goblin Mage";let secondToLastLetter = enemy[enemy.length - 2];console.log(secondToLastLetter);"g"
Thank you for reading my blog! This is the sixth of my series on JavaScript so if you would like to read more, please follow!
See the Next Level Here
Support and Buy me a Coffee
Original Link: https://dev.to/devcronin/level-up-with-javascript-lvl-6-17ff
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To