.valueOf()
yash.ladekar7 total contributions
Published Jun 21, 2021Updated Jun 12, 2023
Contribute to Docs
The .valueOf()
method returns the value of all the elements of the original array.
Syntax
array.valueOf();
Examples
Create a new array with the same elements as programmingLanguages
:
const programmingLanguages = ['JS', 'Python', 'Java', 'C++'];const newArray = programmingLanguages.valueOf();console.log(newArray);// Output: ['JS', 'Python', 'Java', 'C++']
Note: This method will not change the original array. However, if the original array or the variable which holds it (using the
.valueOf()
method) is manipulated, the value of the array will change accordingly.
Codebyte Example
The example below uses the .valueOf()
method to return the fruits
array and assign it to a variable myBag
. The code then makes changes to the original fruits
array by pushing a new element Pineapple
. And the value of myBag
will also change because it holds a reference to the same fruits
array.
All contributors
- yash.ladekar7 total contributions
- Anonymous contributorAnonymous contributor3071 total contributions
- Christine_Yang271 total contributions
- christian.dinh2476 total contributions
- Anonymous contributorAnonymous contributor95 total contributions
- yash.ladekar
- Anonymous contributor
- Christine_Yang
- christian.dinh
- Anonymous contributor
Looking to contribute?
- Learn more about how to get involved.
- Edit this page on GitHub to fix an error or make an improvement.
- Submit feedback to let us know how we can improve Docs.