最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I reverse order, byte wise, of a string in JavaScript? - Stack Overflow

programmeradmin3浏览0评论

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?

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?

Share Improve this question edited Mar 12, 2015 at 18:31 Shamoon asked Mar 12, 2015 at 18:24 ShamoonShamoon 43.7k101 gold badges332 silver badges628 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 10

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"
发布评论

评论列表(0)

  1. 暂无评论