因此,我将.csv文件转换为一组键值对,我试图打印每个唯一值,并且我试图弄清楚如何检查确保值不相同。例如:
var data = $.csv.toObjects(csv);
将所有内容变为
[
{heading1:"value1_1",heading2:"value2_1",heading3:"value3_1",heading4:"value4_1",heading5:"value5_1"}
{heading1:"value1_2",heading2:"value2_2",heading3:"value3_2",heading4:"value4_2",heading5:"value5_2" }
]
我想检查heading1在两个实例中是否具有相同的值,是否只打印该值的第一个实例。
答案 0 :(得分:0)
将您的数据转换为键值对,其中键是来自" heading1"的值。像这样:
var data = [
{heading1:"value1_1",heading2:"value2_1",heading3:"value3_1",heading4:"value4_1",heading5:"value5_1"},
{heading1:"value1_2",heading2:"value2_2",heading3:"value3_2",heading4:"value4_2",heading5:"value5_2" },
];
var filtered = {};
for (var i = 0, max = data.length; i < max; i++) {
var record = data[i];
if (!filtered[record.heading1]) {
filtered[record.heading1] = {};
}
filtered[record.heading1] = record;
}
var keys = Object.keys(filtered);
for (var i = 0, max = keys.length; i < max; i++) {
console.log(filtered[keys[i]]); // do print
}