Search code examples
javascriptractivejs

Add item to the beginning of the list


I've been using the following code to add new comment to the end of the list:

 ractive.push('BlogPosts.BlogPostId.Comments', newComment);

But now I need to add an item to the beginning of the list. I've looked through ractive documentation but did not succeed in finding the appropriate method.


Solution

  • use unshift method of array:

    ractive.unshift('BlogPosts.BlogPostId.Comments', newComment);