You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
constnumbers=[1,2,3,4,5,6]numbers.splice(3,3,7,8,9)console.log(numbers.splice(3,3,7,8,9))// -> [1, 2, 3, 7, 8, 9] //it removes three item and replace three items
small mistake - in case anyone who copy-pasted the code, got [7, 8, 9] instead of [1, 2, 3, 7, 8, 9] and started questioning life,
this is because the author called the splice() method twice, and splice() would modify the original array.
Corrected version:
constnumbers=[1,2,3,4,5,6]console.log(numbers.splice(3,3,7,8,9))// [4, 5, 6] - returns the removed itemsconsole.log(numbers)// [1, 2, 3, 7, 8, 9] - returns current the array numbers
The text was updated successfully, but these errors were encountered:
small mistake - in case anyone who copy-pasted the code, got [7, 8, 9] instead of [1, 2, 3, 7, 8, 9] and started questioning life,
this is because the author called the
splice()
method twice, andsplice()
would modify the original array.Corrected version:
The text was updated successfully, but these errors were encountered: