LoginSignup
3
1

More than 5 years have passed since last update.

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

Last updated at Posted at 2018-07-25

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

方法1

flatten( )を使う

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

方法2

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

  • example
> 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