JavaScript replace 2つめの引数が関数のサンプル

環境
Google Chrome 113.0.5672.127(Official Build

構文
文字列.replace(引数1, function (arg) {処理コード})
2つめの引数は関数(function)です。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const strA = "STCDE";
console.log(
strA.replace("C", function (arg) {
return arg.toLowerCase();
})
);
const strA = "STCDE"; console.log( strA.replace("C", function (arg) { return arg.toLowerCase(); }) );
const strA = "STCDE";
console.log(
  strA.replace("C", function (arg) {
    return arg.toLowerCase(); 
  })
);

実行結果
> “STcDE"

JavaScript

Posted by arkgame