JS Array Methods

Array toString() Method

The JavaScript Array toString() Method returns the string representation of the array elements

Syntax:

arr.toString()

Parameters: This method does not accept any parameter.

Return value: 

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Rahul","Karan","Aman","Neha"];
	a.toString();
	document.write(a + "<br><br>");
  </script>
</head>
<body>
</body>
</html>

Array valueOf() Method

The JavaScript Array 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. 

<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Rahul", "Karan", "Aman", "Neha"];
	document.write(a.valueOf() + "<br><br>");
  </script>
</head>
<body>
</body>
</html>

Array fill() Method

The fill() method fills specified elements in an array with a value.

The fill() method overwrites the original array.

Start and end position can be specified. If not, all elements will be filled.


Syntax

array.fill(value, start, end)

Parameters

Parameter Description
value Required.
The value to fill in.
start Optional.
The start index (position).
Default is 0.
end Optional.
The stop index (position).
Default is array length.

Return Value

Type Description
Array The filled array.
<!DOCTYPE html>
<html>
<head>
  <title>JavaScript</title>
  <script>
    var a = ["Rahul", "Karan", "Aman", "Neha"];
	a.fill("Ram");
	document.write(a);
  </script>
</head>
<body>
</body>
</html>