Y.Array
A shared type to store data in a sequence-like data structure
import * as Y from 'yjs'
const ydoc = new Y.Doc()
// You can define a Y.Array as a top-level type or a nested type
// Method 1: Define a top-level type
const yarray = ydoc.getArray('my array type')
// Method 2: Define Y.Array that can be included into the Yjs document
const yarrayNested = new Y.Array()
// Nested types can be included as content into any other shared type,
// notice that a shared type can only exist once in a document.
yarray.insert(0, [yarrayNested])
// Common methods
yarray.insert(0, [1, 2, 3]) // insert three elements
yarray.delete(1, 1) // delete second element
yarray.toArray() // => [1, 3]API
Observing changes: Y.ArrayEvent
Y.ArrayEvent API
Last updated
