Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
The valueOf()
method is the default behavior for an array. It converts an array to a primitive value. JavaScript will
automatically convert an array to a string when a primitive value is expected. Because of this, all these examples will
produce the same result.
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("example1").innerHTML = fruits;
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("example2").innerHTML = fruits.valueOf();
var fruits = ["Banana", "Orange", "Apple", "Mango"];
document.getElementById("example3").innerHTML = fruits.toString();