Home >>JavaScript Array Reference >JavaScript Array valueOf() Method

JavaScript Array valueOf() Method

JavaScript Array valueOf() Method

JavaScript valueOf() method is used to return the given input array. It does not change the original given array. It does not contain any parameter value.

Syntax:
array.valueOf()

Browser Support

Method Chrome Edge Firefox Safari Opera
valueOf() Yes Yes Yes Yes Yes
Here is an example of JavaScript valueOf() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction()
{
  var x = ["A", "B", "C", "D", "E", "F"];
  document.getElementById("demo").innerHTML = x.valueOf();
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1()
{
  var x = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  document.getElementById("demo1").innerHTML = x.valueOf();
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads