Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139863

Updating back of array without using push() in javascript

$
0
0

I am trying to update the back of an array WITHOUT using the push() function, so I decided to use the splice() function and pass -1, and 0, and then the value so that it would update my array at the last index. I am then trying to return the length of the updated array, which should be 5.

function push(array, value) {
  var upDatedArray = array.splice(-1, 0, value);
  var lengthArray = upDatedArray.length;
  return lengthArray;
}

console.log (
  push([1, 2, 3, 4, 5], 6)
  );

What am I doing wrong here? Because it keeps returning 0, rather than the desired '5' length that I am looking for?


Viewing all articles
Browse latest Browse all 139863

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>