Skip to content

Instantly share code, notes, and snippets.

@chuck0523
Created August 23, 2015 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chuck0523/9fedec8c9645f6bf2398 to your computer and use it in GitHub Desktop.
Save chuck0523/9fedec8c9645f6bf2398 to your computer and use it in GitHub Desktop.
# Array
a = [1, 3, 5]
b = [
1
3
5
]
# a bの中身は同じ値。ただしbの場合、インデントは必須
# ..
# 0~5
m = [0..5]
# 0~4
n = [0...5]
console.log m[1..3] # 1, 2, 3
console.log m[..3] # 0, 1, 2, 3
console.log m[1..] # 1, 2, 3, 4, 5
console.log m[..] # 0, 1, 2, 3, 4, 5
console.log m[1..-2] # 1, 2, 3, 4
m[0..1] = ['a', 'b', 'c'] # a, b, c, 2, 3, 4, 5
console.log m
console.log 'world'[1..3] # orl
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment