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);
As you can see the code are similar logic, just the splice method is place after the Array.from
or in a newArr
, but the result is very different, the errnewArr
got the length: 1, but the new array
got the length: 3.
Why the result is look like that?