Petar
1
function fruitInventory(arr) {
let arrCopy = […arr]
arrCopy[0][1] -= 1;
console.log(arr)
console.log(arrCopy)
}
(fruitInventory([ [“APPLE”, 6] , [“ORANGE”, 2]]));
Result:
[ [ ‘APPLE’, 5 ], [ ‘ORANGE’, 2 ] ]
[ [ ‘APPLE’, 5 ], [ ‘ORANGE’, 2 ] ]
Hi @Petar,
The spread operator creates a shallow copy of an array.
Link below explains it in detail:
1 Like
Petar
3
Thank you very much @manjupillai16 , very clear.
system
Closed
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.