我正在尝试通过获取以
checkpoint
开头的每个键并输出其值来过滤对象。目前,我只能输出键而不是值。下面是一个简单的对象。我正在使用filter和startsWith。如何获取值?
var data = {
practicals: '0',
checkpoint01: '0',
checkpoint02: '0',
checkpoint03: '0',
checkpoint04: '0',
checkpoint05: '0',
checkpoint06: '0',
checkpoint07: '0',
checkpoint08: '0',
checkpoint09: '0',
checkpoint10: '0',
total: '0'
}
var res = Object.keys(data).filter(v => v.startsWith('checkpoint'))
console.log(res)
// This is the current output: ["checkpoint01", "checkpoint02", "checkpoint03", "checkpoint04", "checkpoint05", "checkpoint06", "checkpoint07", "checkpoint08", "checkpoint09", "checkpoint10"]
// This is the expected output I want: [ '0', '0', '0', '0', '0', '0', '0', '0', '0', '0' ]