How to use valueof() Method In Javascript
The valueOf() method returns the primitive value of an array. Again the returned string will separate the elements in the array with commas. There is no difference between toString() and valueOf(). Even if we try with different data types like numbers, strings, etc it would give the same result.
Example:
javascript
let array = [ "geeks" , "4" , "geeks" ]; let csv = array.valueOf(); console.log(csv); |
Output
[ 'geeks', '4', 'geeks' ]
Converting JavaScript Arrays into CSVs and Vice-Versa
Converting Arrays into CSVs: Given an array in JavaScript and the task is to obtain the CSVs or the Comma Separated Values from it. Now, JavaScript being a versatile language provides multiple ways to achieve the task.
Some of them are listed below.
- Using the toString() method
- Using valueof() Method
- Using the join() function
- Using the split() function
Contact Us