11种JavaScript生成1到100的数组的方式
11 种 JavaScript 生成 1 到 100 的数组的方式
# 循环赋值
var arr = new Array(100); | |
for(var i=0;i<arr1.length;i++){ | |
arr1[i] = i; | |
} |
11 种 JavaScript 生成 1 到 100 的数组的方式
var arr = new Array(100); | |
for(var i=0;i<arr1.length;i++){ | |
arr1[i] = i; | |
} |
npm install -g json-server |
整个文件相当于一个数据库,每一个属性相当于一个表是一个数组,它里面的每个对象代表一条数据,* 切记里面的每个对象都要有 id,不写他就会自动生成 *
{ | |
"posts": [ | |
{ "id": 1, "title": "json-server", "author": "typicode" } | |
], | |
"comments": [ | |
{ "id": 1, "body": "some comment", "postId": 1 } | |
], | |
"profile": { "name": "typicode" } | |
} |
// 增加 | |
addItem: function () { | |
var n = this.signForm.signFormList ? this.signForm.signFormList.length + 1 : 1; | |
this.signForm.signFormList.push({ | |
title: '标题' + n, | |
require: false | |
}); | |
}, | |
// 删除 | |
removeItem: function (item) { | |
const index = this.signForm.signFormList.indexOf(item); | |
this.signForm.signFormList.splice(index, 1); | |
}, | |
// 置顶 | |
moveTop: function (item) { | |
const index = this.signForm.signFormList.indexOf(item); | |
if(index != 0){ | |
this.signForm.signFormList.splice(index,1); | |
this.signForm.signFormList.splice(0,0,item); | |
} | |
}, | |
// 上移 | |
moveUp: function (item) { | |
const index = this.signForm.signFormList.indexOf(item); | |
if(index != 0){ | |
this.signForm.signFormList.splice(index,1); | |
this.signForm.signFormList.splice(index-1,0,item); | |
} | |
}, | |
// 下移 | |
moveDown: function (item) { | |
const index = this.signForm.signFormList.indexOf(item); | |
const max = this.signForm.signFormList.length ; | |
if(index != max){ | |
this.signForm.signFormList.splice(index,1); | |
this.signForm.signFormList.splice(index+1,0,item); | |
} | |
}, |