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

2
  • 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. This is a duplicate of JavaScript chop/slice/trim off last character in string Commented May 8, 2021 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). Commented May 8, 2021 at 19:39

1 Answer 1

0

try this:

var a = "hello everyone"
var b = a.slice(a.length-3)
console.log(b)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.