2

so I added a prompt('Enter something);. then for example I entered 'Hello world!' then I want this to have only 5 characters. So it will return 'Hello'. if I entered 'something', it will return 'somet'. how do I do that in JavaScript?

apologies if there's another question like this.

plop
  • 88
  • 7
  • 1
    Does this answer your question? [JavaScript chop/slice/trim off last character in string](https://stackoverflow.com/questions/952924/javascript-chop-slice-trim-off-last-character-in-string) – shreyasm-dev Nov 05 '20 at 02:53

1 Answers1

2

You could use .slice

const input = prompt('Enter something');

alert(input.slice(0, 5))
hgb123
  • 13,869
  • 3
  • 20
  • 38