I have a string that represent array:
context.something.1.nothing
The regex pattern would be: \\.\\d+
.
How to replace it to the following format:
context.something[1].nothing
Of course the array can be any length.
You could accomplish it in the following way ....
var arr = 'context.something.1.nothing'; var newArr = arr.replace(/\\.(\\d+)/, '[$1]'); console.log(newArr);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.