The "replace" function only works once by default, so it only replaces the first space with an underscore. Add the quantifier 'g' to change it to 'global' to make it work on the entire string:
var myLinkNewName = myLink.filePath.replace(/ /g, "_");
Perfect. Thanks, Jongware.
One more question, this code is not working if my links name has [solidus] character i.e., edu_s/ch7_pg01_col.eps. Could you please let me know what code is require in my script so that it relinks all the links whether it has [underscore] with [solidus].
var myLinkNewName = myLink.filePath.replace(/ /g, "_").replace(/\//g, "_");
Thanks for your answer and valuable suggestion.