Code 1:
let targetArr = ["hello", "world", "my", "name"];
let errnewArr = Array.from(targetArr).splice(2, 1);
console.log("errnewArr array : " + errnewArr.length);
Code 2:
targetArr = ["hello", "world", "my", "name"];
let newArr = Array.from(targetArr);
newArr.splice(2, 1);
console.log("new array : " + newArr.length);
These two code snippets share a common logic, with the splice method being placed after Array.from
or in a newArr
. However, they yield very different results. While errnewArr
has a length of 1, the new array
has a length of 3.
What could be causing this disparity in outcomes?