Avatar ·

How to add a new element to the beginning of an array in JavaScript?

Hi everyone! I just started learning JavaScript and ran into this problem. I have an array with numbers, for example: `let numbers = [2, 3, 4, 5];`. I want to add the number `1` to the very beginning, so it becomes `[1, 2, 3, 4, 5]`. I know that to add to the end of an array there is the `push()` method, and I use it: `numbers.push(6)` — and it works perfectly, the element is added to the end. But what if I need to insert an element at the beginning? I tried writing `numbers[0] = 1`, but that replaces the first element, not adds a new one. That is, the array becomes `[1, 3, 4, 5]`, but I need all the old elements to shift to the right. I've heard there is some `unshift()` method, but I'm not sure if I understood it correctly. And another question: if I want to add several elements at once to the beginning, is that possible?