Y.Array can not insert element

const yarray = new Y.Array();
yarray.insert(0, [1, 2, 3]);
console.log(yarray.toArray()); // output is: [], expected output: [1,2,3]

Is this expected behavior?

Your YTypes need to be linked to a Y.Doc in order to be “active”, so to speak. So

const ydoc = new Y.Doc()
const yarray = ydoc.getArray('someArray')
yarray.insert(0, [1,2,3])
yarray.toArray() // [1,2,3]

would work. Or, you can nest yTypes in each other and it will work, as long as there’s a “path” of yTypes back to the yDoc.

const ymap = ydoc.getMap('someMap')
const yarray = new Y.Array();
ymap.set('key', yarray)
yarray.insert(0, [1,2,3])
yarray.toArray() // [1,2,3]