Last active
April 27, 2022 16:27
-
-
Save megabayt/dbb677fa9ab6ef779f15d6426716d0a6 to your computer and use it in GitHub Desktop.
May be useful if you need to save empty values
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const m = 4; | |
const n = 3; | |
const matrix = [ | |
[1, 2], | |
[3, 4, 5], | |
[6, 7, 8, 9], | |
]; | |
const arr = []; | |
for (let i = 0; i < n; i++) { | |
for (let j = 0; j < m; j++) { | |
arr[m * i + j] = matrix[i][j]; | |
} | |
} | |
console.log(arr); // [1, 2, undefined, undefined, 3, 4, 5, undefined, 6, 7, 8, 9] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment