Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How exclude string part from main string that has in array by javascript

I have string that exist in array as follow

getid Array [
  "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2",
]

I want to exclude this part E8R52y6dD8XI3shXhnhS9pVzUpe2 from that ,

actually E8R52y6dD8XI3shXhnhS9pVzUpe2 this is user.uid .
this is two user id combine id "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2"
this combine id exist in arrays.
so many combine id will has in this array.
I want to exclude user.uid E8R52y6dD8XI3shXhnhS9pVzUpe2 from all combine id .
if exclude user.uid , there will be remain one id part in this array.
I want to get this remain part of id value to use.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

let userid = E8R52y6dD8XI3shXhnhS9pVzUpe2
let combineId = ["E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2","E8R52y6dD8XI3shXhnhS9pVzUpe26Lh5bHrzCSvI2bmoMv7KuduMGwe2","E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2"]

// this is value what i want
let remainIdinArray = ["6Lf5bHwzCSbI2bmoMv7KuduMGwe2","6Lh5bHrzCSvI2bmoMv7KuduMGwe2","6Lf5bHwzCSbI2bmoMv7KuduMGwe2"]

how can do that.
thanks

>Solution :

You can use the map and the slice!


    let userid = "E8R52y6dD8XI3shXhnhS9pVzUpe2";
    let combineId = [
      "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2",
      "E8R52y6dD8XI3shXhnhS9pVzUpe26Lh5bHrzCSvI2bmoMv7KuduMGwe2",
      "E8R52y6dD8XI3shXhnhS9pVzUpe26Lf5bHwzCSbI2bmoMv7KuduMGwe2"
    ];
    
    let remainIdinArray = combineId.map((id) => id.slice(-userid.length));
    
    console.log(remainIdinArray);

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading