Skip to content

Instantly share code, notes, and snippets.

@sho-t
Created May 25, 2018 01:27
Show Gist options
  • Save sho-t/215455f9fe603f74e5d040203614e749 to your computer and use it in GitHub Desktop.
Save sho-t/215455f9fe603f74e5d040203614e749 to your computer and use it in GitHub Desktop.
javascript雑記
// 2次元配列の初期化
[...Array(3)].map(() => Array(3).fill(0));
const foo = { a: 1, b: 2 };
// オブジェクトのクローン
const bar = { ...foo }; // => { a: 1, b: 2 }
// 特定の値の分割代入
let kbyd = ['輿水幸子', '姫川友紀', '小早川紗枝'];
let [, yakyu] = kbyd;
// 多次元配列をオブジェクトに
var obj = Object.assign(...arr.map(d => ({[d[0]]: d[1]})));
// 多次元配列を回転
const invert = a => a[0].map((col, c) => a.map((row, r) => a[r][c]));
// 多次元配列からundefindを除去
const rmv = a => a.map((a) => a.filter((e) => e !== undefined));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment