DEV Community


Discussion on: How do I get the first/last char of a string from a user input (input.value)

donnii profile image
Daniel Dark

And here is what you want:

submit.addEventListener('click', () => {

    const {value} = yourName

    const firstChar = value.slice(0, 1)
    const lastChar = value.slice(-1)

    welcome.textContent = firstChar + lastChar
Thread Thread
morrisjohn profile image
Morris John Author • Edited

Wow, that worked.

I don't even understand the code (*LOL I haven't learnt the 'const / {} => yet *) but yeah it worked.

Thank you very much