array-spread

1.0.2 • Public • Published

array-spread

Why

Concat a matrix array into one flattened array.

Installation

$ npm install --save array-spread

Usage

var arraySpread = require('array-spread');
 
var matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
 
console.log(arraySpread(matrix));
 
// Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]

Test

npm test

How does it work?

var matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
 
console.log([].concat.apply([], matrix));
 
// Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]

ES6

let matrix = [
    [1, 2, 3],
    [4, 5, 6],
    [7, 8, 9]
];
 
console.log([...matrix]);
// Output:
[1, 2, 3, 4, 5, 6, 7, 8, 9]

Contribution

Contributions are appreciated.

License

MIT-licensed. See LICENSE.

Package Sidebar

Install

npm i array-spread

Weekly Downloads

1

Version

1.0.2

License

MIT

Last publish

Collaborators

  • bjarneo