applyArrayPath = function (key, arrayPath) {
  var depth = 0;
  if (!key) return null;
  if (!arrayPath || (arrayPath.length === 0)) return key;
  var newKey = key.replace(reArray, function (str, p1) {
    // Note this function gets called as many times as there are [x] in the ID,
    // from left to right in the string. The goal is to replace the [x] with
    // the appropriate index in the new array path, if defined.
    var newIndex = str;
    if (isSet(arrayPath[depth])) {
      newIndex = '[' + arrayPath[depth] + ']';
    }
    depth += 1;
    return newIndex;
  });
  return newKey;
}
Applies the array path to the key path.

For instance, if the key path is:
 foo.bar[].baz.toto[].truc[].bidule
and the arrayPath [4, 2], the returned key will be:
 foo.bar[4].baz.toto[2].truc[].bidule

@function
@param {String} key The path to the key in the schema, each level being
 separated by a dot and array items being flagged with [].
@param {Array(Number)} arrayPath The array path to apply, e.g. [4, 2]
@return {String} The path to the key that matches the array path.