Splice an array in half, no matter the size?

Avoid Mutations

If you need to avoid mutations, for example if you have to split an array in react you don't want to mutate the original or it could lead to some very strange behaviour in your app.

What is a Mutation?

A mutation is when you change a non primitive, like an object or array. Using an array method like splice will cause the original array to be manipulated. You can always tell if a method will mutate by whether or not it returns a new array or object.

Why can Mutations be "bad"?

When you mutate an object or array you change that original reference. This means that if you use the original reference you will get the new value. This is best shown with an example.

// make a new object
const myObj = { key: "some value" };

// assign a new const to the object (this is assigned by reference)
const newObj = myObj;

// change the value of a key in the new const
newObj.key = "some other value";

// log the original object and see that its value has been changed
console.log(myObj) // will log { key: "some other value" };

As you can see the object myObj had the value of key changed as well. Scary stuff.

Use Slice

You can get around this by using slice instead of splice

Example

let yourArray = props.someArray;
let halfwayThrough = Math.floor(yourArray.length / 2)
// or instead of floor you can use ceil depending on what side gets the extra data

let arrayFirstHalf = yourArray.slice(0, halfwayThrough);
let arraySecondHalf = yourArray.slice(halfwayThrough, yourArray.length);

var half_length = Math.ceil(arrayName.length / 2);    

var leftSide = arrayName.slice(0,half_length);

edited the code following @Lightness Races in Orbit and @pubkey comments.