From 68e1d9ac0793ecb50fe0959422a061d440dbead6 Mon Sep 17 00:00:00 2001 From: Isabelle Viktoria Maciohsek Date: Sun, 30 Jan 2022 12:23:14 +0200 Subject: [PATCH] Fix formatting --- snippets/CSVToArray.md | 8 +++++--- snippets/CSVToJSON.md | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/snippets/CSVToArray.md b/snippets/CSVToArray.md index 0b940d120..27136aff4 100644 --- a/snippets/CSVToArray.md +++ b/snippets/CSVToArray.md @@ -2,13 +2,15 @@ title: CSVToArray tags: string,array,intermediate firstSeen: 2018-06-27T20:57:54+03:00 -lastUpdated: 2021-10-13T19:29:39+02:00 +lastUpdated: 2022-01-30T12:14:39+02:00 --- 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. +- Use `Array.prototype.indexOf()` to find the first newline character (`\n`). +- Use `Array.prototype.slice()` to remove the first row (title row) if `omitFirstRow` is `true`. +- Use `String.prototype.split()` to create a string for each row. +- Use `String.prototype.split()` to separate the values in each row, using the provided `delimiter`. - 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. diff --git a/snippets/CSVToJSON.md b/snippets/CSVToJSON.md index aea3081cb..9d0e9a414 100644 --- a/snippets/CSVToJSON.md +++ b/snippets/CSVToJSON.md @@ -2,14 +2,16 @@ title: CSVToJSON tags: string,object,advanced firstSeen: 2018-06-27T21:14:24+03:00 -lastUpdated: 2020-11-03T22:11:18+02:00 +lastUpdated: 2022-01-30T12:14:39+02:00 --- Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row. -- Use `Array.prototype.slice()` and `Array.prototype.indexOf('\n')` and `String.prototype.split(delimiter)` to separate the first row (title row) into values. -- Use `String.prototype.split('\n')` to create a string for each row, then `Array.prototype.map()` and `String.prototype.split(delimiter)` to separate the values in each row. +- Use `Array.prototype.indexOf()` to find the first newline character (`\n`). +- Use `Array.prototype.slice()` to remove the first row (title row) and `String.prototype.split()` to separate it into values, using the provided `delimiter`. +- Use `String.prototype.split()` to create a string for each row. +- Use `String.prototype.split()` to separate the values in each row, using the provided `delimiter`. - Use `Array.prototype.reduce()` to create an object for each row's values, with the keys parsed from the title row. - Omit the second argument, `delimiter`, to use a default delimiter of `,`.