Alright, I am in the process of transforming an array into another array by displacing indexes based on arbitrary points from two reference arrays. This operation introduces negative indexes which unfortunately hinders the functionality of the script. Is there a way to enable the second array with negative indexes and have the script still work? Or will I need to seek out an entirely new approach? I have simplified the code below.
var firstArray = {
field: [ 1, 2, 3, 4, 5],
referenceIndex : 2
};
var secondArray = {
referenceIndex: 1,
offset: 0,
field : {}
};
// Calculating the offset for secondArray.field.
secondArray.offset = firstArray.referenceIndex - secondArray.referenceIndex;
for (i=0; i < firstArray.field.length; i++){
alert([i - secondArray.offset, firstArray.field[i]].join(" "));
secondArray.field[i - secondArray.offset] = firstArray.field[i]; // Handling negative indexing.
}