Foreword: Note that Array[3]on your console output, this is how the console displays it to you. Your newArrreally:
["Martin", 78, 67, ['L', 'M', 'P']]
This is because it is defined as slice. In short:
- Creates a new empty array
- Reads the property
lengthof what you give it - Passes from start index (default
0) to end index (default length - 1); call loop variablek length k - start.
( ):
function slice(start, end) {
var n, k, result;
start = arguments.length < 1 ? 0 : +start;
end = arguments.length < 2 ? +this.length : +end;
result = [];
for (var k = start, n = 0; k < end; ++k, ++n) {
if (n in this) {
result[n] = this[k];
}
}
result.length = n;
return result;
}
gory.
arrLike length 0, 1, 2 3, , .