0

I want to ask my ignorance about javascript I gave a little description, hopefully I can understand what I mean

example:

var a = `hello everyone`
var b = a.slice (6)
console.log (b)

output = everyone

how can I change the slice from the back like this:

var a = `hello everyone`
var b = a.slice (3)
console.log (b)

output = one

VLAZ
  • 26,331
  • 9
  • 49
  • 67
  • 2
    To maintain the quality of the site, we don't allow duplicate questions here. Please use the search function or your preferred search engine to perform at least *some* research before posting here, in accordance with [How to Ask](https://stackoverflow.com/help/how-to-ask). This is a duplicate of [JavaScript chop/slice/trim off last character in string](https://stackoverflow.com/questions/952924/javascript-chop-slice-trim-off-last-character-in-string) – esqew May 08 '21 at 19:31
  • @esqew are you sure it's a dupe? The title seems *very* different from the body of this question. OP seems to want the last few characters. The question you linked to is about *removing* the last few characters. The answers there show either how to take characters *from the beginning* or otherwise just removing from the end (not even via `.slice()` exclusively). – VLAZ May 08 '21 at 19:39

1 Answers1

0

try this:

var a = "hello everyone"
var b = a.slice(a.length-3)
console.log(b)
VLAZ
  • 26,331
  • 9
  • 49
  • 67
Laurenz1606
  • 88
  • 13