Skip to content

Instantly share code, notes, and snippets.

@thomasxbanks
Created June 15, 2017 08:35
Show Gist options
  • Select an option

  • Save thomasxbanks/be489c555c70c786397debe0e95208d8 to your computer and use it in GitHub Desktop.

Select an option

Save thomasxbanks/be489c555c70c786397debe0e95208d8 to your computer and use it in GitHub Desktop.
Assigns row number and column number to an array of objects
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