JSFiddle - React, Tailwind, and code Playground

by skirtle

HTML

<div id="output1"></div>
<div id="output2"></div>

JavaScript

const data = [
  [0],
  [1],
  [2],
  [3, 1, 2, 3, 4, 'This one', 6, 7]
]

const getByIndexes = (value, indexes) => {
  for (const index of indexes) {
    value = value[index]
  }
  
  return value
}

const setByIndexes = (value, indexes, newValue) => {
  const path = [...indexes]
  const property = path.pop()
  
  getByIndexes(value, path)[property] = newValue
}

document.getElementById('output1').innerText = getByIndexes(data, [3, 5])

setByIndexes(data, [3, 5], 'That one')

document.getElementById('output2').innerText = JSON.stringify(data)