You can create a helper function
function findValueByPrefix(object, prefix) {
for (var property in object) {
if (object.hasOwnProperty(property) &&
property.toString().startsWith(prefix)) {
return object[property];
}
}
}
findValueByPrefix(obj, "key1");
As Kenney commented, the above function will return first match.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…