Basic JavaScript Day 2: Homework

This is the perfect case to play a bit with the code, break things and discover yourself what happens! :smiling_face_with_three_hearts: By the way, it is possible in various different ways for example you can transform the digits in a string using .toString() (if they are not a string already) and then use the brackets as an array since a string can be seen as an array of characters. Taking your example:

const arr = [1, 2, 23847];
const singleDigit = arr[2].toString()[2] // it takes the third element 23847 and transforms it into a String then you use again the bracket notation to take a single digit 8
console.log(singleDigit) // output 8
2 Likes

Thank you sooo much~ :star_struck: So happy to learn something new!

2 Likes

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.