Get #Amazon #Prime for this #holiday #amazonprime #christmas #2019

#JavaScript - use Google Chrome developer tool to #splice and #slice

If you want to practice or experiment with what you read on JavaScript documents such as on MDN, you can open up a browser's developer tool and write your code there. To do that, you can right click and select 'inspect' on Google Chrome to open up the developer tool.

Google Chrome Inspector
Google Chrome Inspector

For example, to check what splice and slice actually do. You can do the following:
On MDN, splice and slice are defined as the following:
The splice() method changes the contents of an array by removing existing elements and/or adding new elements.
The slice() method returns a shallow copy of a portion of an array into a new array object selected from begin to end (end not included). The original array will not be modified.

Note that splice mutates the original array while slice creates a new array.

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr.length // 10
var splicedArr = arr.splice(0, 2)
splicedArr.length // 2
splicedArr
arr.length // 8
arr

var arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
arr.length // 10
var slicedArr = arr.slice(0, 2)
slicedArr.length // 2
slicedArr
arr.length // 10, same as before
arr 

JavaScript Splice Example
JavaScript Splice Example

JavaScript Splice Second Example
JavaScript Splice Second Example

JavaScript Slice Example
JavaScript Slice Example

Thank you for reading!

Jun