over 9 years ago
JavaScript Array valueOf() method : The valueOf() method returns the copy of itself. This is the default method of an array object.
Syntax of Array valueOf() method :
Example of Array valueOf() method : In this example I will show how to create a copy of an array.
- <!DOCTYPE html>
- <html>
- <body>
- <p>To make a copy of an array, click the button "copy".</p>
- <button onclick="copyArray()">copy</button>
- <p id="container"></p>
- <script>
- function copyArray() {
- var students = ["Rajesh", "Pankaj", "Sumit", "Manish", "Pramod"];
- document.getElementById("container").innerHTML = students.valueOf();
- }
- </script>
- </body>
- </html>
<!DOCTYPE html> <html> <body> <p>To make a copy of an array, click the button "copy".</p> <button onclick="copyArray()">copy</button> <p id="container"></p> <script> function copyArray() { var students = ["Rajesh", "Pankaj", "Sumit", "Manish", "Pramod"]; document.getElementById("container").innerHTML = students.valueOf(); } </script> </body> </html>
Output :
Rajesh,Pankaj,Sumit,Manish,Pramod
Can you help out the community by solving one of the following Javascript problems?
Do activity (Answer, Blog) > Earn Rep Points > Improve Rank > Get more opportunities to work and get paid!
For more topics, questions and answers, please visit the Tech Q&A page.
0 Comment(s)