Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript get second last element in array

const myNumbers = [100, 200, 300, 400, 500];
// option one
const seconLastNumber = myNumbers.slice(-2, -1)[0]) // 400

// option two
const seconLastNumber = myNumbers[numbers.length - 2]; // 400
Comment

javascript get second last element of array

const numbers = ["one", "two", "three", "four"];
console.log(numbers[numbers.length - 2]);
Comment

js get last n elements of array

const cars = ["benz", "bmw", "volvo", "skoda"];

const lastThree = cars.slice(-3);

console.log(lastThree); // ["bmw", "volvo", "skoda"]
Comment

PREVIOUS NEXT
Code Example
Javascript :: delete file with deno 
Javascript :: jquery get fail 
Javascript :: call python function from javascript 
Javascript :: check all checkboxes on table 
Javascript :: get the length of an object vuejs 
Javascript :: Find Smallest Number by function in Javascript 
Javascript :: javascript select from array where 
Javascript :: how to know the current route in react class component 
Javascript :: react bootstrap table 
Javascript :: change react native app name 
Javascript :: javascript spread operator 
Javascript :: js anonymous function es6 
Javascript :: how to get current date in express js 
Javascript :: window location any web 
Javascript :: loop inside react js 
Javascript :: js falsy values 
Javascript :: pass param to url retrofit 
Javascript :: nestjs 
Javascript :: js date in arabic 
Javascript :: { use UnifiedTopology: true } 
Javascript :: get value of textarea jquery 
Javascript :: javascript for in loop 
Javascript :: listing range in javascript 
Javascript :: loop array of objects 
Javascript :: Using Then To Create A Promise In JavaScript 
Javascript :: onclick delete self 
Javascript :: cra proxy 
Javascript :: javascript get next dom element 
Javascript :: js get copied text 
Javascript :: mongoosejs 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =