msg.slice(0,2); code example Example: cut string from string javascript var ret = "data-123".replace('data-',''); console.log(ret); //prints: 123