(js)循环数组构建对象

(js)循环数组构建对象


数组

dataArr=["企业","工序"]

方法

//构建表头 
dataArr.forEach((item) => {
  let obj = {};
  obj = {
    label: item,
    value: item,
  };
  this.headList.push(obj);
});

对象

this.headList = [
  {
    label: "企业",
    value: "企业",
  },
  {
    label: "工序",
    value: "工序",
  },
];

你可能感兴趣的:(JS,javascript,前端,开发语言)