Created
June 15, 2017 08:35
-
-
Save thomasxbanks/be489c555c70c786397debe0e95208d8 to your computer and use it in GitHub Desktop.
Assigns row number and column number to an array of objects
This file contains hidden or 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 array = [{}, | |
| {}, {}, {}, | |
| {}, {}, {}, | |
| {}, {}, {}, | |
| {}, {} | |
| ] | |
| let columnCount = 4 | |
| let count = 1 | |
| const loop = (index) => { | |
| (index % columnCount) ? count: count++ | |
| return count - 1 | |
| } | |
| array.forEach((item, index) => { | |
| item.title = index | |
| item.row = loop(index) | |
| item.col = (index % columnCount + 1) | |
| console.log(item) | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment