Javascript Snippets

Cast to String

Problem:

('1234' === 1234) // false 
String(string); // 'hello'
String(number); // '123'
String(boolean); // 'true'
String(array); // '1,2,3'
String(object); // '[object Object]'
String(symbolValue); // 'Symbol(123)'
String(undefinedValue); // 'undefined'
String(nullValue); // 'null'

or

var s = 123456 + '';

https://medium.com/dailyjs/5-ways-to-convert-a-value-to-string-in-javascript-6b334b2fc778

Using Class and prototype

https://raindrop.io/collection/2707120?q=tag:prototype&sort=-sort

Using fetch to download files

fetch('example.txt')
.then(response => response.text()) 
.then(textString => {
    console.log(textString);
});
fetch('example.csv')
.then(response => response.text()) 
.then(csvString => {
    const rows = csvString.split('\n');
    for (row of rows) {
        console.log(row.split(","));
    }
});