Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Index of Y.Array in forEach method starts from 1 #485

Open
stellit opened this issue Nov 17, 2022 · 0 comments
Open

Index of Y.Array in forEach method starts from 1 #485

stellit opened this issue Nov 17, 2022 · 0 comments
Assignees
Labels

Comments

@stellit
Copy link

stellit commented Nov 17, 2022

Describe the bug
Index of Y.Array in forEach start from 1
It seems that the issue only affect 14.0.0-0

To Reproduce

test('yarray-index-test', () => {
    const doc = new Y.Doc();
    const yArr = doc.getArray('');
    yArr.push(['elem 1', 'elem 2']);
    yArr.forEach((elem, index, arr) => {
        console.log(`index: ${index}`); // starts from 1
        arr.get(index); // error will be thrown when get the last element with index.
    });
});

It seems that the index got increased by this line: https://github.com/yjs/yjs/blob/v14.0.0-0/src/utils/ListCursor.js#L313

Expected behavior
index in the forEach should starts from 0,

Environment Information

  • Yjs version: v14.0.0-0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants