The at() method takes an integer value and returns the item at that index, allowing for positive and negative integers. Negative integers count back from the last item in the array.

EX:

  1. To get last element in array we always do array\[array.length -1\] instead we could simple call array.at(-1)
  2. array\[array.length -2\] → array.at(-2)
// Our array with items
const numbers = [1, 2, 3];

// Using length property
const lengthWay = numbers[numbers.length-2];
console.log(lengthWay); // Logs: 2

// Using at() method
const atWay = colors.at(-2);
console.log(atWay); // Logs: 2

--

--

useFallbackState

useFallbackState is almost same as useState, but it takes 3 props instead of 1.

1st prop is the same -> default value.

2nd prop is the state from the parent. It’s optional if parent doesn’t send a prop then local useState’s value will be used.

3rd prop is the setState from the parent. This callback will be called every time state changes.

--

--