On another jscript forum i found the following sample code that helps me greatly on a problem i have posted on this forum.
However, running this piece of code i am getting error:
microsoft jscript runtime error property or method not supported by object.
Error arises on line with RegExp. I don't understand why.
any help appreciated.
var mapObj = {cat:"dog",dog:"goat",goat:"cat"};
var re = new RegExp(Object.keys(mapObj).join("|"),"gi");
str = str.replace(re, function(matched){
return mapObj[matched];
});
Replace multiple string and regexp
Moderator: DosItHelp
-
- Posts: 208
- Joined: 26 Dec 2013 09:28
- Contact:
Re: Replace multiple string and regexp
Object.keys is not defined in ms/jscript. The code you posted throws error because ms/jscript doesn't support many features. However it can be successfully run under nodejs. You need use nodejs or define Object.keys on your own.
Re: Replace multiple string and regexp
I got this suspect…. Many thanks : I’ll study nodejs.