일단 완료되면 기본 대수 방정식을 계산하는 js 함수가 있습니다. 어떤 이유로 배열에서 문자열의 첫 번째 문자를 대체 할 수 없습니다. 이전에이 함수에서 사용했지만 작동하지 않습니다. 나는 .substring()뿐만 아니라 .replace()를 사용해 보았습니다.자바 스크립트는 문자열의 첫 번째 문자를 벗어날 수 없습니다.
이 내가 해봤 다음 코드는 다음과 같습니다 콘솔에
// this is what i've been testing it on
// $problem[o][j] = +5
var assi = $problem[0][j].charAt(0); // Get the first character, to replace to opposite sign
switch (assi){
case "+":
console.log($problem[0][j]);
$problem[0][j].replace("+","-");
console.log($problem[0][j]);
break;
}
위의 출력 : I 시도
> +5
> +5
다음 코드 :이가 출력
// Second code i tried with $problem[0][j] remaining the same
switch(assi){
case "+":
console.log($problem[0][j]);
$problem[0][j].substring(1);
$problem[0][j] = "-" + $problem[0][j];
console.log($problem[0][j]);
break;
}
은 콘솔 :
> +5
> -+5
는 또한 = a.replace이 (...)'A * 새 문자열 개체를 만들고 '참고 교체 된 문자열을 저장 *와 *는'a' *에 할당합니다. 따라서'a '를 수정해야한다면 다음을 할 수 있습니다 :'a = a.replace (...)' – techfoobar