我有一个类似以下的对象:

var RevenueCodes = {
            41020: "Addendum",
            41040: "Cardiology Assessment",
            41060: "Chiropractic Assessment",
            41290: "Neurology File Review - CAT",
            41240: "Neurology Assessment"
            }


如果使用JavaScript搜索“附录”,如何找到号码?

最佳答案

您可以使用for...in枚举对象属性。



var RevenueCodes = {
  41020: "Addendum",
  41040: "Cardiology Assessment",
  41060: "Chiropractic Assessment",
  41290: "Neurology File Review - CAT",
  41240: "Neurology Assessment"
};
for (var propertyName in RevenueCodes) {
  if (RevenueCodes[propertyName] === "Addendum") {
    console.log("property name: %s", propertyName);
    break;
  }
}

10-06 00:19