.replace javascript not working -


hi working in java script have string

var data = 'http://baab.bh/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/t/e/test.jpg'; 

i want replace /image/ 'image/440x600' using function

.replace()

but not working here code

var data ='http://baab.bh/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/t/e/test.jpg';     data.replace('/image/', '/image/440x600/');     console.log(data); 

its showing same not replacing /image/ 'image/440x600'.

strings in javascript immutable. cannot modified.

the replace method returns modified string, doesn't modify original in place.

you need capture return value.

var data = 'http://baab.bh/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/t/e/test.jpg';  data = data.replace('/image/', '/image/440x600/');  console.log(data);


Comments

Popular posts from this blog

Spring Boot + JPA + Hibernate: Unable to locate persister -

go - Golang: panic: runtime error: invalid memory address or nil pointer dereference using bufio.Scanner -

c - double free or corruption (fasttop) -