+ 3
why wasn't "E" pushed to the num array ?
var num = ["A", "B", "C"]; var special= num.splice(num.push("D"), num.push("E"), "Z"); document.write(num); //prints A,B,C,D,Z
4 ответов
+ 5
It was pushed to the num array. But it got replaced by "Z".
+ 4
Marina
"E" was pushed to the array, but since you are using the array push method as parameters for the array splice method, "E" was cut from the array.
var special = num.splice(num.push("D"), num.push("E"), "Z"); starting at index 4 remove 5 position and replace with an "Z"
Splice - returns new Array, containing the removed items (if any)-w3schools.com
document.write(special);//prints E
+ 4
Marina
If you do not specify any elements to add, splice() will only remove elements from the array.
Read more
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice
[Edit a few months later]: I try to understand this answer now but I can't??
Downvoted myself.
+ 1
Kevin Star so why when i remove " Z " , it doesn't print " E " ?