0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScript Substringの使い方

Posted at

概要

文字列を任意の箇所で切り取ることができます。

i番目から次の文字からj番目までを切り取ります。

substring(i,j) //jは省略可能
let hello = "hello";
//指定した番号から切り取ります
console.log(hello.substring(1)); //ello
console.log(hello.substring(4)); //o

console.log(hello.substring(0, 1)); //h
console.log(hello.substring(1, 3)); //hel
//lengthを使用
console.log(hello.substring(0, hello.length)); //hello
console.log(hello.substring(0, hello.length -1)); //hell
console.log(hello.substring(2, hello.length -1)); //ll

###参考
MDN substring

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?