I have a an array being passed to me which is something like
var arr = ["A", "B", "C"];
What I am trying to achieve is to only get the first and last value so it should look like
var arr = ["A", "C"];
I'm not how to achieve this using splice
because when I do
arr.splice(I am not sure what numbers to put here).forEach(function (element) {
console.log(element);
});
Can someone tell me how to achieve this please.
What I am trying to achieve is to only get the first and last value so it should look like
Simply
arr.splice( 1, arr.length - 2 );
Demo
var arr = ["A", "B", "C"];
arr.splice(1, arr.length - 2);
console.log(arr);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With