Post

I bet you didn't know this. In a technical interview, you might be asked how to get the last element of an array. Well, there are three options, and you might like the last one best.

  • const latest = arr[arr.length - 1];
  • const latest = arr.slice(-1)[0];

And this one 😜
#JavaScript #FrontEnd #Developers #InterviewQuestions

      const arr = [1, 2, 3, 4];
const latest = arr.at(-1);
console.log(latest); // 4
    
JS Developers
JS Developers

JS Developers

Software Developer

We are a specialized tool that integrates you into a private Circle of 5 people. It's a shared responsibility system for founders, developers, and students.

Developed in EU