阅读:5924回复:3
关于new Array().fill()的用法
当我们想借助new Array()生成指定数组长度的假数据的时候,我们可以这样写:
const data = new Array(5).map((v, i) => { return { name: "XXX" + i, price: i, category: Math.random() > 0.5 ? '蔬菜' : '水果' } }) console.log(data) // (5) [empty × 5] 以下便是关于new Array().fill的用法了 const data = new Array(5).fill().map((v, i) => { return { name: "XXX" + i, price: i, category: Math.random() > 0.5 ? '蔬菜' : '水果' } }) console.log(data) // (5) [{…}, {…}, {…}, {…}, {…}] //0: {name: "XXX0", price: 0, category: "蔬菜"} //1: {name: "XXX1", price: 1, category: "蔬菜"} //2: {name: "XXX2", price: 2, category: "蔬菜"} //3: {name: "XXX3", price: 3, category: "水果"} //4: {name: "XXX4", price: 4, category: "水果"} //length: 5 //__proto__: Array(0) |
|
沙发#
发布于:2020-09-29 09:57
|
|
板凳#
发布于:2020-09-29 10:04
苍穹总结:
let n = res.data.data.length this.zhanbieOptions = new Array(n).fill().map((v, i) => { return { lable: "" , value: "", } }) for(var i = 0;i<res.data.data.length;i++){ this.zhanbieOptions.lable = res.data.data.STEP_NAME this.zhanbieOptions.value = res.data.data.STEP_ID } |
|
地板#
发布于:2020-09-29 13:15
修改每条SQL语句 20200929 13:06 备份于此地:
let allsqls = this.sql.sqls let n = allsqls.length let indexs = new Array(n).fill().map((v, i) => { return { "" } }) for(var i = 0;i<allsqls.length;i++){ let indexWh = sqls.indexOf('where') let sqlBefore = sqls.substring(0,indexWh-1) ……………… } |
|