Ask coding questions

← Back to all posts
How do i get character off the end of a string in js
JacobMcPherson1

how do i get the first 11 characters off a string in javascript

Answered by ch1ck3n [earned 5 cycles]
View Answer
Voters
JacobMcPherson1
Comments
hotnewtop
ch1ck3n

str.substring(11);

JacobMcPherson1

@ch1ck3n I'm using this in a bookmarklet and it's not working

JacobMcPherson1

I'm getting this error

ch1ck3n

@JacobMcPherson1 it's location.href.substring(11)

JacobMcPherson1

@ch1ck3n ohhh alright thanks

samfierycreeper

@JacobMcPherson1, you can substring()

let myRandomVariable = "Hello World!!!"
let otherVariable = myRandomVariable.substring(0, 5)
console.log(otherVariable) <-- prints the string "Hello"

Substring is a used for exactly what you're trying to do.

substring(character_you_want_to_start_with, character_you_want_to_end_with)