Some easy to miss points

Original link: https://zburu.com/archives/158.html

  • When listening to the object, if the value is null, an error will be reported, and the default value is set to {};
  • for in can only traverse the object i in 4 is a wrong way of writing;
  • Dynamically obtain arrays – splicing parameters
 var arr = [ "单位1", "单位2", "单位3", "单位4", "单位5" ]
 // 1.数组[] for (var i = 0; i < arr.length; i++) { this.defaultData.hostUnitList.push({ [arr[i]]: this.defaultData[arr[i]] }); }
 // 2.对象{} for (var i = 0; i < arr.length; i++) { this.defaultData.hostUnitList[arr[i]] = this.defaultData[arr[i]] }

This article is reproduced from: https://zburu.com/archives/158.html
This site is for inclusion only, and the copyright belongs to the original author.

Leave a Comment