Question #14

Author: admin
tags: JavaScript  
const arr1 = [10, 20, [7, 9], 30, [2, 4, [15]], 80];

// const arr2 = *** // Here we make a copy of the array

arr2[2][0] = 8; // We change the value in the copy array, it should not change in the original array.

console.log(arr2[2][0]); // 8
console.log(arr1[2][0]); // Should be 7, not 8
Which line should be inserted instead of *** so console.log(arr1[2][0]); outputs 7?
arr2 = JSON.parse(JSON.stringify(arr1));
arr2 = arr1;
arr2 = arr1.slice();
arr2 = [].concat(arr1);
arr2 = [...arr1];
arr2 = Object.assign([], arr1);
None of the listed lines, the number 8 will be output everywhere instead of the required number 7.
The JSON.stringify trick works well in this case.
Rate the difficulty of the question:
easyhard