Converts a comma-separated values (CSV) string to a 2D array.

Use Array.prototype.slice() and Array.prototype.indexOf('\n') to remove the first row (title row) if omitFirstRow is true.
Use String.prototype.split('\n') to create a string for each row, then String.prototype.split(delimiter) to separate the values in each row.
Omit the second argument, delimiter, to use a default delimiter of ,.
Omit the third argument, omitFirstRow, to include the first row (title row) of the CSV string.

继续阅读 30秒学会 JavaScript 片段 – CSVToArray

Returns the target value in a nested JSON object, based on the given key.

Use the in operator to check if target exists in obj.
If found, return the value of obj[target], otherwise use Object.values(obj) and Array.prototype.reduce() to recursively call dig on each nested object until the first matching key/value pair is found.

继续阅读 30秒学会 JavaScript 片段 – dig

Pads a string on both sides with the specified character, if it’s shorter than the specified length.

Use String.prototype.padStart() and String.prototype.padEnd() to pad both sides of the given string.
Omit the third argument, char, to use the whitespace character as the default padding character.

继续阅读 30秒学会 JavaScript 片段 – pad