「JavaScript」slice()で文字列の一部を取得するサンプル

2021年4月30日

書式
文字列.slice(位置,マイナス数値)
使用例

<script>

      const cftA = "this is a test";
      
      console.log(cftA.slice(0,-1)); 
      console.log(cftA.slice(0,-2)); 
      
      console.log(cftA.slice(1,-1)); 
      console.log(cftA.slice(1,-2)); 
</script>

実行結果
this is a tes
this is a te
his is a tes
his is a te

JavaScript

Posted by arkgame