Skip to content
Related Articles

Related Articles

How to delete all occurrences of a particular string using Vue.js ?

View Discussion
Improve Article
Save Article
  • Last Updated : 11 Apr, 2022

In this article, we are going to learn how to delete all occurrences of a particular word using filters in VueJS. Vue is a progressive framework for building user interfaces. Filters are a functionality provided by Vue components that let you apply formatting and transformations to any part of your template dynamic data. The filter property of the component is an object. A single filter is a function that accepts a value and returns another value. The returned value is the one that’s actually printed in the Vue.js template.

The occurrence of a particular word can be deleted by using filters on the required string. We will use the JavaScript split() method to split the string on the particular target word that has to be deleted. This will return an array that split at the points where that particular word occurs except the word that was used to split the string. Finally, we will join the array using the join() method and return the resulting string.



  <script src=
  <div id='parent'>
      <strong>Original String: </strong>
      <strong>After Delete: </strong
      {{ st1 | delete('computer') }}
      <strong>Original String: </strong>
      <strong>After Delete: </strong
      {{ st2 | delete('language') }}
  <script src='app.js'></script>


const parent = new Vue({
  el: '#parent',
  data: {
    st1: 'GeekforGeeks is a computer science\
          portal. computer science is the study\
          of algorithmic processes, computational\
          machines and computation itself',
    st2: 'C++ is a best language for competitive
          programming, Javascript is best\
          for scripting language',
  filters: {
    delete: function (st, target) {
      const result = st.split(target).join('')
      return result;


My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!