I have ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f
and I want 7fb9c0
....
I am using lodash
and where's what I have so far
mytxid = 'ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f'
reverseTxid = _.chunk mytxid.split(''), 2
reverseTxid = reverseTxid.reverse()
reverseTxid _.flattenDeep reverseTxid
However, I get an error on the .reverse()
: [TypeError: object is not a function]
What am I doing wrong and what's a better way to do it?
You can split the String into bytes by matching every two hex digits, reverse the returned array, then join the array back into a String:
var s = "ded3e8c2e3460a97500c09d752a83c4eb44eda90998e33ce8d346a1174c0b97f";
s.match(/[a-fA-F0-9]{2}/g).reverse().join('')
// "7fb9c074116a348dce338e9990da4eb44e3ca852d7090c50970a46e3c2e8d3de"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With