function exportTimestampsWithErrors(data) {
if (!Array.isArray(data)) {
console.error("Input must be an array.");
return [];
}
const results = [];
for (let i = 0; i < data.length; i++) {
const item = data[i];
if (typeof item !== 'object' || item === null) {
console.error(`Element at index ${i} is not a valid object. Skipping.`);
results.push({ timestamp: null, error: "Invalid object format" });
continue;
}
if (!item.timestamp) {
console.error(`Element at index ${i} is missing 'timestamp' property.`);
results.push({ timestamp: null, error: "Missing 'timestamp' property" });
continue;
}
if (typeof item.timestamp !== 'number') {
console.error(`Element at index ${i} has invalid 'timestamp' type. Expected number.`);
results.push({ timestamp: null, error: "Invalid 'timestamp' type. Expected number." });
continue;
}
results.push({ timestamp: item.timestamp, error: null });
}
return results;
}
Add your comment