遍历对象再取值,获得新值
作者:互联网
获取对象数组里某些特定的属性值,在组合成新的对象数组,并返回
getObjKeysAndValue(object, str) { const voltData = []; for (let i in object) { if (i.indexOf(str) != -1) { const obj = {}; obj[i] = object[i]; voltData.push(obj); } } return voltData; },
用法:
const optionData = this.getObjKeysAndValue(input, "volt_");
input: { pf_b: 1000, power_a: 157, volt_c: 0, pf_a: 778, pf_c: 1000, current_a: 84, energy_a: 22147, volt_a: 2404, energy_c: 0, energy_b: 0, power_b: 0, current_b: 0, power_c: 0, current_c: 0, volt_b: 0 },
标签:遍历,const,voltData,energy,新值,current,volt,pf,取值 来源: https://www.cnblogs.com/hahahakc/p/14484966.html