Pen Settings



CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ add another resource


Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource


Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.


Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.


                <body onload="attachArray()">
         <h1>Splice vs Slice</h1>
         <label for="main">Starting Array</label>
         <div class="container">
             <div class="array-display" id="main"></div>
             <button type="button" onclick="attachArray()" >Refresh</button>
         <h3>Using slice()</h3>
         <div class="container">
             <label>Start Index</label>
             <input id="sliceStart" type="number" value="0">
             <label>End Index</label>
             <input id="sliceEnd" type="number" value="3">
             <button type="button" onclick="sliceArray()" >Slice</button>
         <label>New Array</label>
         <div class="array-display" id="newArray"></div>
         <h3>Remove with splice()</h3>
         <div class="container">
             <label>Start Index</label>
             <input id="spliceStart" type="number" value="3">
             <label>Number of Items to Remove</label>
             <input id="spliceEnd" type="number" value="7">
             <button type="button" onclick="removeWithSplice()" >Remove with Splice</button>
         <h3>Add with splice()</h3>
         <div class="container">
             <label>Start Index</label>
             <input id="spliceStartAdd" type="number" value="3">
             <label>Number of Items to Remove</label>
             <input id="spliceEndAdd" type="number" value="0">
             <label>Value to Add</label>
             <input id="spliceAddValue" type="text">
             <button type="button" onclick="addWithSplice()" >Add with Splice</button>


                container {
    display: flex;
    flex-wrap: wrap;
    flex-direction: row;

.array-display {
    font-color: #444;
    font-style: italic;
    padding: 10px;

body {
    font-family: Arial, Helvetica, sans-serif;

label {
    font-weight: 600;
    margin: 0px 10px 10px 0px;

button {
    padding: 9px 8px;
    border-radius: 5px;
    border-width: 1px;
    border-color: gray;
    background: rgb(222,222,222);
    background: linear-gradient(90deg, rgba(222,222,222,1) 0%, rgba(205,205,205,1) 35%, rgba(188,188,188,1) 100%);

input {
    padding: 5px;
    border-radius: 4px;
    border-width: 1px;
    border-color: dodgerblue;


                let colors = ["Red", "Orange", "Yellow", "Green", "Blue", "Purple", "White", "Black", "Gray", "Brown"];

function attachArray() {
    let mainDiv = document.getElementById("main");
    mainDiv.innerHTML = colors;

function sliceArray() {
    let startIndex = document.getElementById("sliceStart").value;
    let endIndex = document.getElementById("sliceEnd").value;
    let newArrayDiv = document.getElementById("newArray");
    let slicedColors = colors.slice(startIndex, endIndex);
    newArrayDiv.innerHTML = slicedColors;

function removeWithSplice() {
    let startIndex = document.getElementById("spliceStart").value;
    let endIndex = document.getElementById("spliceEnd").value;
    colors.splice(startIndex, endIndex);

function addWithSplice() {
    let startIndex = document.getElementById("spliceStartAdd").value;
    let endIndex = document.getElementById("spliceEndAdd").value;
    let valueToAdd = document.getElementById("spliceAddValue").value;
    colors.splice(startIndex, endIndex, valueToAdd);