Answers for "slice method js in java"

1

return last two values of array in javascript

arr.slice(Math.max(arr.length - 5, 1))
Posted by: Guest on March-01-2020
15

array.slice

const animals = ['ant', 'bison', 'camel', 'duck', 'elephant'];

console.log(animals.slice(2));
// expected output: Array ["camel", "duck", "elephant"]

console.log(animals.slice(2, 4));
// expected output: Array ["camel", "duck"]

console.log(animals.slice(1, 5));
// expected output: Array ["bison", "camel", "duck", "elephant"]
Posted by: Guest on July-30-2020

Code answers related to "Javascript"

Browse Popular Code Answers by Language