How to return all except last 2 characters of a string?

You are looking for slice() (also see MDC)

id.slice(0, -2)

Try id.substring(0, id.length - 2);