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] 配列の主な操作をまとめてみた

Last updated at Posted at 2021-01-20

##はじめに
Javascriptの配列の操作方法について調べてみたので備忘録として残す

##配列を操作するメソッド

###※配列を作成
下記の配列をもとに進める

let test = ['a', 'b']

console.log(test.length)
// 2

###位置を指定して配列にアクセスする

test[0]
// a

test[fruits.length - 1]
// b

###配列に値を追加

test.push('c')
// ['a', 'b', 'c']

###配列に末尾を削除

test.pop()
// ['a', 'b']

###配列に銭湯に値を追加

test.unshift('z')
// ['z', 'a', 'b']

###要素の添字を取得

test.indexOf('a')
// 1

###要素の添字を取得

test.indexOf('a')
// 1

###配列をコピー

let testCopy = test.slice()
// ['z', 'a', 'b']

###配列の長さを取得

test.length
// 3

###配列を逆に入れ替え

test.reverse()
// ['b', 'a', 'z']

##参考
https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array

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?