Data structure with ids

Here’s where I am so far with deduplication: with my class’ get content (), I’m calling this deduplication with both the live DOM and the current PM doc:

function domMutationDedupeIds (domChildren, doc) {
  let ids = []
  let len = domChildren.length
  for (let i=0; i<len; i++) {
    let child = domChildren[i]
    let id = child.getAttribute('data-grid-id')
    if (!id || ids.indexOf(id) !== -1) {
      id = uuid.v4()
      // Need to set it in both dom and doc for future consistency
      child.setAttribute('data-grid-id', id)
      doc.content[i].attrs.id = id
    }
    ids.push(id)
  }
}

Feels dangerous to set it both the DOM and the doc like that. Is there a cleaner way that I’m missing?