JavaScript Array valueOf() Method

Below is the example of Array valueOf() method.

  • Example:
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <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>

    chevron_right

    
    

  • 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:

filter_none

edit
close

play_arrow

link
brightness_4
code

<!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>

chevron_right


Output:

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

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

full-stack-img




My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.