d3.csvParse
时间: 2023-12-13 22:04:22 浏览: 85
d3.csvParse is a function provided by the d3.js library, which is used for parsing CSV (Comma-Separated Values) files in JavaScript. It takes a string of CSV data as input and returns an array of objects, where each object represents a row in the CSV file. Each property of the object corresponds to a column in the CSV file, with the property names derived from the CSV headers.
Here's an example usage of d3.csvParse:
```javascript
const csvData = `name,age,city
John,25,New York
Jane,30,San Francisco
Bob,35,Chicago`;
const parsedData = d3.csvParse(csvData);
console.log(parsedData);
```
Output:
```
[
{ name: "John", age: "25", city: "New York" },
{ name: "Jane", age: "30", city: "San Francisco" },
{ name: "Bob", age: "35", city: "Chicago" }
]
```
In the example above, the `csvData` string represents a CSV file with three columns: "name", "age", and "city". The `d3.csvParse` function is used to parse this data into an array of objects, where each object represents a row in the CSV file. Finally, the parsed data is logged to the console.
阅读全文