In the JavaScript array there is not any in-built replace() methods for replacing elements but we can implement replace() method by using the in-built splice() method. We have already discussed the splice() method in our JavaScript array tutorial.
In the JavaScript array there is not any in-built replace() methods for replacing elements but we can implement replace() method by using the in-built splice() method. We have already discussed the splice() method in our JavaScript array tutorial.In the JavaScript array there is not any in-built replace() methods for replacing elements but we can implement replace() method by using the in-built splice() method. We have already discussed the splice() method in our JavaScript array tutorial. For implementation of replace() method we have created a replace() method which takes three arguments as given below:
function replace(arrayName,replaceTo, replaceWith)
|
Above code is the function defined for implementing replace() method.
replace(arr,"Suman","Vineet"); Here we have passed "Vineet" to be replaced by the array element "Suman".
Full code of javascript_array_replace.html is as follows:
<html>
|
Output of the example is as follows:
Ads