I have an array of objects for example I want to replace the key normal with value www.test.com/is/images/383773?@HT_dtImage. I am using .replace with regex to basically replace the wid and hei with @HT_dtImage
const urls = [
{"normal": "www.test.com/is/images/383773?wid=200&hei=200",
"thumbnail": "www.test.com/is/images/383773?wid=200&hei=200"},
{"normal": "www.test.com/is/images/383773?wid=200&hei=200",
"thumbnail": "www.test.com/is/images/383773?wid=200&hei=200"},
{"normal": "www.test.com/is/images/383773?wid=200&hei=200",
"thumbnail": "www.test.com/is/images/383773?wid=200&hei=200"}
]
I tried using a .map like this which just returns the original object.
const updateImages = images => {
images.map(image => {
return image.normal.replace(/\b(?:wid|hei)=[^&]*&?/g, "") + "@HT_dtImage"
});
return images;
};
I also tried this but it returns it in an array without not as an array with objects. I feel like I'm just missing something simple.
const updateImages = images => {
return images.map(image => {
return image.normal.replace(/\b(?:wid|hei)=[^&]*&?/g, "") + "@HT_dtImage"
})
};
The expected output I am looking for is
const urls = [
{"normal": "www.test.com/is/images/383773?@HT_dtImage",
"thumbnail": "www.test.com/is/images/383773?wid=200&hei=200"},
{"normal": "www.test.com/is/images/383773?@HT_dtImage",
"thumbnail": "www.test.com/is/images/383773?wid=200&hei=200"},
{"normal": "www.test.com/is/images/383773?@HT_dtImage",
"thumbnail": "www.test.com/is/images/383773?wid=200&hei=200"}
]

@HT_dtImages in it, while leaving the original one unchanged?@HT_dtImagein it while leaving the original inputimagesunchanged.mapwas not the right method butforEachwas.