-1

I have a string for example:-

String: Notification 'Arcosa-Incident assigned to my group' 8ff7afc6db05eb80bfc706e2ca96191f included recipients as manager of a group in the notification's "Groups" field: 'Ruchika Jain' 9efa38ba0ff1310031a1e388b1050e3f

So basically i convert it into an array using .split(' ') method to make it comma separated values, now i want to filter this array and want only values which are 32 character long and remove rest of values.

Please help me achieve this. Alternate solutions are also welcomed. Thanks in advance.

adiga
  • 34,372
  • 9
  • 61
  • 83
ManojS
  • 9
  • 1
  • 4
    Possible duplicate of [Filter array by string length in javascript](https://stackoverflow.com/questions/28768952/filter-array-by-string-length-in-javascript) and [JScript: Take as input an array of strings, return new array containing only strings with fewer than five characters](https://stackoverflow.com/questions/40177669) – adiga Mar 01 '19 at 19:54

2 Answers2

0

Assuming you want to grab those IDs you can simply use a regex with match on the string without splitting/filtering it. (Note: I had to escape the single quotes in the text.)

const str = 'String: Notification \'Arcosa-Incident assigned to my group\' 8ff7afc6db05eb80bfc706e2ca96191f included recipients as manager of a group in the notification\'s "Groups" field: \'Ruchika Jain\' 9efa38ba0ff1310031a1e388b1050e3f';

const matches = str.match(/[a-f0-9]{32}/g);
console.log(matches);
Andy
  • 61,948
  • 13
  • 68
  • 95
-1

Like so:

var arr = ...;
var filtered = arr.filter(word => word.length === 32);

Edit: this may be a bad idea if you want to parse only the GUIDs. It could certainly be that a name like "Ruchika" is also 32 characters long. Maybe, consider using regular expressions instead.

D.R.
  • 20,268
  • 21
  • 102
  • 205