Togliere la prima parte della stringa javascript

Esempi di codice

9
0

N

let str = " hello";
str = str.substring(1);
7
0

N

var newStr = str.substring(1);
1
0

N

// this will replace the first occurrence of "www." and return "testwww.com"
"www.testwww.com".replace("www.", "");

// this will slice the first four characters and return "testwww.com"
"www.testwww.com".slice(4);

// this will replace the www. only if it is at the beginning
"www.testwww.com".replace(/^(www\.)/,"");
1
0

N

// Hey buddy, here are different implementation, choose your favourite !!

// best implementation
const removeChar = (str) => str.slice(1, -1);

// regex
function removeChar(str) {
  return str.replace(/^.|.$/g, "");
}

// without slice
function removeChar(str) {
  const array = str.split("");
  let res = "";
  for (let i = 1; i < array.length - 1; i++) res += array[i];
  return res;
}
0
0

N

let str = 'ss';

str = new RegExp('^.(.*)').exec(str)[1]; // "s"

In altre lingue

Questa pagina è in altre lingue

Русский
..................................................................................................................
English
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................