slice string into segments of 2 characters 1

slice string into segments of 2 characters

var str = "7831154D207D4E2A20515236393D263F7679157374841E5E";
console.log(str.match(/.{1,2}/g));	//78, 31, 15 ...

Here is what the above code is Doing:
1. The first line is a string of hexadecimal characters.
2. The second line is a regular expression that matches every two characters.
3. The third line is a call to the match() method of the string.
4. The fourth line is a call to the console.log() method.

The match() method returns an array of strings. Each string in the array is two characters long.

Similar Posts