Skip to content
Related Articles

Related Articles

Improve Article

JavaScript Array valueOf() Method

  • Last Updated : 25 Jun, 2020

Below is the example of Array valueOf() method.

  • Example:




    <script>
    function func() { 
          
        // Original array 
        var array = ["GFG", "Geeks", "for", "Geeks"]; 
      
        // Checking for condition in array 
        var value = array.valueOf(); 
      
        document.write(value);
      
    func();
    </script>
  • Output:
    GFG,Geeks,for,Geeks

The arr.valueOf() method in JavaScript is used to return the array. It is a default method of the Array Object. This method returns all the items in the same array. It will not change the original content of the array. It does not contain any parameter values.

Syntax:

array.valueOf()

Parameters: This method does not accept any parameter.

Return Value: It returns an Array.



Below examples illustrate the JavaScript Array valueOf() method:

  • Example:
    var array = ["DS", "Algo", "PHP", "JS", "OS"]; 
    var value = array.valueOf(); 
    document.write(value);

    Output:

    DS,Algo,PHP,JS,OS

Example codes for the above method are as follows:
Example:




<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript Array valueOf() Method
    </title>
</head>
  
<body style="text-align:center;">
      
    <h1 style="color:green"
        GeeksforGeeks
    </h1>
  
    <h2>JavaScript Array valueOf() Method</h2>
  
    <button onclick="myGeeks()">Click me</button>
  
    <p id="sudo" style="font-size:20px;"></p>
  
    <script>
        function myGeeks() {
            var sub = ["DS", "Algo", "PHP", "JS", "OS"];
              
            document.getElementById("sudo").innerHTML
                    = sub.valueOf();
        }
    </script>
</body>
  
</html>

Output:

Supported Browsers: The browsers supported by JavaScript Array valueOf() Method are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Safari
  • Opera



My Personal Notes arrow_drop_up
Recommended Articles
Page :