return last two values of array in javascript
arr.slice(Math.max(arr.length - 5, 1))var arr1 = [0, 1, 2, 3, 4, 5, 6, 7],
arr2 = [0, 1, 2, 3];
document.body.innerHTML = 'ARRAY 1: ' + arr1.slice(1).slice(-5) + '<br/>ARRAY 2: ' + arr2.slice(1).slice(-5);
Also in JavaScript:
- javascriopt initialize 2d array with size
- reusable table in react js
- concantene number in js
- javascript constructor function
- short string javascript
- next js newsletter
- how to set time out in js
- boble sorting javascript
- jquery onchange input value
- jquery validation plugin
- check if file exists javascript
- number to array js
- scroll to top
- fibonacci javascript
- define all jsdoc typedef in a seperate file
- js promiseStatus
- jquery select element inside element
- jQuery AJAX form submit
- javascript get element by tag and attribute
- jquery OR operation
- javascript navigator.mediaDevices.getUserMedia
- count number of checkboxes in html jquery
- add to json object javascript
- jquery number format thousand k