Reputation: 1520
Looking for the most efficient way to change this string 000
into [0][0][0]
.
Upvotes: 0
Views: 61
Reputation: 8376
One more way would be to use regular expression, such that
'000'.replace(/0/g, '[0]')
Upvotes: 4
Reputation: 63587
How about using split
and join
:
'[' + '000'.split('').join('][') + ']'
Or with a regex with replace
:
'000'.replace(/\d/g, function (el) { return '[' + el + ']'; })
Upvotes: 4