diff --git a/src/set-key-value.js b/src/set-key-value.js index 8220295..5ffb292 100644 --- a/src/set-key-value.js +++ b/src/set-key-value.js @@ -126,16 +126,43 @@ function _setValue(destinationObject, key, keys, fromValue) { if (Array.isArray(fromValue) && _isNextArrayProperty(keys) === false) { for (valueIndex = 0; valueIndex < fromValue.length; valueIndex++) { value = fromValue[valueIndex]; - destinationObject[key][arrayIndex + valueIndex] = _setValue(destinationObject[key][arrayIndex + valueIndex], keys[0], keys.slice(1), value); + var targetIndex = arrayIndex ? parseInt(arrayIndex) : parseInt(valueIndex); + destinationObject[key][targetIndex] = _setValue(destinationObject[key][targetIndex], keys[0], keys.slice(1), value); } } else { - destinationObject[key][arrayIndex] = _setValue(destinationObject[key][arrayIndex], keys[0], keys.slice(1), fromValue); + var findFirstIndexWithoutProp = function(keys, array) { + for(var i=0;i