3
1

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 5 years have passed since last update.

多次元配列を1次元配列に変換

Last updated at Posted at 2018-07-25

JavaScriptで多次元配列を1次元配列に変換する方法

方法1

flatten( )を使う

  • install
.shell
npm install flatten
  • example
.js
> var flatten = require('flatten');
> var array = [['a','b','c'],['d']];
> console.log(flatten(array));
  [ 'a', 'b', 'c', 'd' ]

方法2

Array.prototype.concat.apply( )を使う

  • example
.js
> var array = [['a','b','c'],['d']];
> console.log(Array.prototype.concat.apply([],array));
[ 'a', 'b', 'c', 'd' ]
3
1
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
3
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?