Cómo establecer el tipo de valor de cadena al número en js

var text = '42px';
var integer = parseInt(text, 10);
// returns 42
Mohamad