Destruction assignment JavaScript - swaping places of array items

Hello, I’m trying to swap places of two elements of the array using the destruction assignment but it is not working, here is my code

  let array = [23, 34, 45];
  [array[0], array[2]] = [array[2], array[0]]

It’s throwing an error "Cannot set property ‘45’ of undefined’, why is that happening?

here’s some info about deconstruction

go to javascript.info for more help

// dont forget to add const or let'
[array[0], array[2]] = [array[2], array[0]]

for let array = [23, 34, 45];you would have something like this

// let arr = ['foo', 'bar']
/*
'''
instead of assigning a single variable name
you can assign a variable name for each item in the array
eg.
let a = 'foo'
let b = 'bar'

to do this from the array you would say
let a = arr[0] // 'foo'
let b = arr[1] // 'bar'

a nicer looking way to say this exact same thing is to
just name each item like every other variable, but you put
them before the = sign
'''
*/
let [a,b] = ['foo', 'bar'] // returns a as 'foo' and b as 'bar'

enjoy

I understand it but what I did wrong in my code? How it should look like then?

is this your whole code?
only these two lines work fine

let array = [23, 34, 45];
  [array[0], array[2]] = [array[2], array[0]]
console.log(array); // [45, 34, 23]

there may be something else in your editor that is throwing that error

this was the question, this error is not generated by the shown code snippet - so I was asking if there is anything else in the editor