Skip to content

Home.svelte > addPost > Array splicing #1

@fjanon

Description

@fjanon

First, thanks a million for your tutorial, it's helping a lot with Svelte.

Just a detail: if I am not mistaken, postsUpdated can be dropped and we can apply splice on posts, since posts and postsUpdated point both at the same array...

postsUpdated = posts and posts = postsUpdated don't copy the arrays, they point to the same array so no need to assign posts and postsUpdated

function addPost({ detail: post }) { if (posts.find(p => p.id === post.id)) { const index = posts.findIndex(p => p.id === post.id); let postsUpdated = posts; postsUpdated.splice(index, 1, post); posts = postsUpdated;

function addPost({ detail: post }) { if (posts.find(p => p.id === post.id)) { const index = posts.findIndex(p => p.id === post.id); posts.splice(index, 1, post);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions