Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

remove duplicate value from string

// remove duplicate value from string
let str = "a b a";
let words = str.toLowerCase().split(" ");

const remDuplicate = words.filter((data,index,src)=>{
  return src.indexOf(data)===index
})

console.log("remDuplicate =>",remDuplicate)
Comment

remove duplicate from string

// Java program to create a unique string
import java.util.*;
  
class IndexOf {
      
    // Function to make the string unique
    public static String unique(String s)
    {
        String str = new String();
        int len = s.length();
          
        // loop to traverse the string and
        // check for repeating chars using
        // IndexOf() method in Java
        for (int i = 0; i < len; i++) 
        {
            // character at i'th index of s
            char c = s.charAt(i);
              
            // if c is present in str, it returns
            // the index of c, else it returns -1
            if (str.indexOf(c) < 0)
            {
                // adding c to str if -1 is returned
                str += c;
            }
        }
          
        return str;
    }
  
    // Driver code
    public static void main(String[] args)
    {
        // Input string with repeating chars
        String s = "geeksforgeeks";
          
        System.out.println(unique(s));
    }
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: text overflow ellipsis two lines react native 
Javascript :: create select option using jquery 
Javascript :: map list in javascript 
Javascript :: lodash remove multiple items from array 
Javascript :: base64 encoded data to object in javascript 
Javascript :: js copy paragraph onclick 
Javascript :: Redirect to any page after 5 seconds in Javascript 
Javascript :: how to loop through something in node.js 
Javascript :: check time javascript 
Javascript :: jshint ignore line 
Javascript :: EACCES: permission denied 
Javascript :: falsy values javascript 
Javascript :: jquery get img src 
Javascript :: mongodb add key value to all documents 
Javascript :: javascript parse date dd/mm/yyyy hh:mm:ss 
Javascript :: jquery cget lineheight in pixels 
Javascript :: jquery: select select box rpogramatically 
Javascript :: javascript reload page without refresh 
Javascript :: jquery code to make click function 
Javascript :: array.from js 
Javascript :: jquery fadeout to fadein 
Javascript :: unidirectional data flow react 
Javascript :: javascript get element by id and class 
Javascript :: web3 js get network 
Javascript :: mocha config 
Javascript :: axios.interceptors.response.use 
Javascript :: react router dom change default path 
Javascript :: reverse json.stringify 
Javascript :: mongoose search by name 
Javascript :: dynamically added button onclick not working 
ADD CONTENT
Topic
Content
Source link
Name
2+8 =