tencent cloud

Tencent Cloud Observability Platform

dataset.forEach

PDF
포커스 모드
폰트 크기
마지막 업데이트 시간: 2025-03-11 19:41:14
During the script execution, dataset.forEach can traverse the given parameter files, supporting modification and deletion operations. It is mainly used in the setup function.
forEach(fileName: string, callback: (item: Item, i?: number) => void): void

Parameters

Parameter
Type
Description
fileName
string
The names of the parameter files that are traversed.
callback
function
The callback function; item is of Item type, representing a row of data in the parameter file; i is of numeric type, representing the row number of that row of data.

Return

Type
Description
void
No content returned.

Samples

Traverse the parameter file, and perform modifications and deletions:
import dataset from 'pts/dataset';

export function setup() {
// Traverse the parameter file named 'test.csv'.
dataset.forEach('test.csv', (item) => {
// Change the data value of the key 'key5' in the data row item to '555'.
item.data.key5 = '555';
// If the data value of the key 'key1' in the data row item is '1', mark it as deleted, and it will not be used during the execution of this script.
if (item.data.key1 === '1') {
item.delete();
}
});
}
Traverse the parameter file, including the i parameter in the callback function:
import dataset from 'pts/dataset';

export function setup() {
// Traverse the parameter file named 'test.csv'.
dataset.forEach('test.csv', (item, i) => {
// Output.
// 0: {"name":"1","value":"111"}
// 1: {"name":"2","value":"222"}
// 2: {"name":"3","value":"333"}
console.log(i, ': ', JSON.stringify(item.data));
});
}


도움말 및 지원

문제 해결에 도움이 되었나요?

피드백