批改状态:合格
老师批语:总结的还不错,好好练习
// 队列arr = ['a','b','c','d']function que1(arr, str){arr.push(str)arr.shift()}console.log(arr);que1(arr, 'e')console.log(arr);que1(arr, 'f')console.log(arr);// 循环队列arr = ['a','b','c','d']function que2(arr){let a = arr.shift()arr.push(a)}console.log(arr);que2(arr)console.log(arr);que2(arr)console.log(arr);for(let key of arr.entries()){console.log(key);}
列队(4) ['a', 'b', 'c', 'd'](4) ['b', 'c', 'd', 'e'](4) ['c', 'd', 'e', 'f']循环列队(4) ['a', 'b', 'c', 'd'](4) ['b', 'c', 'd', 'a'](4) ['c', 'd', 'a', 'b']
str = 'Dmegc东磁'console.log(str[3])console.log(str.length)console.log(str.search('e'))console.log(str.replace('e','u'))console.log(str.slice(0,5)) // 拿不到结束索引console.log(str.substr(5,2))console.log(str.split('')) // 切割成数组console.log(str.toLowerCase())console.log(str.toUpperCase())
g72Dmugc东磁Dmegc东磁Array(7)dmegc东磁DMEGC东磁
let arr = []arr.push('a','b','c')console.log(arr)arr.pop()console.log(arr)arr.unshift('A')console.log(arr)arr.shift()console.log(arr);for(let key of arr.entries()){console.log(key);}// arr.keys()/arr.values()/arr.entries()用法相同,得到迭代对象console.log(arr.slice(2, 4));console.log(arr.includes('a'));console.log(arr.splice(3, 4));// arr.splice() 前值为起始位置,后值为删除元素个数,删除对应的数组,并返回;如果有三值,则为插入的元素,如果插入元素为数组,想展开可加...// 排序,a-b升序,b-a降序arr = [3,5,1,9]arr.sort(function(a,b){return a - b})console.log(arr);arr.sort((a,b)=> b - a) // 箭头函数简化console.log(arr);// arr.forEach()// arr.map( )// arr.some()是含有即为true,every()是全部满足为trueconsole.log(arr.every(item=>item > 5)); // 参数支持item值,index索引,arr数组// arr.filter() 返回满足条件的新数组console.log(arr.filter(item=>item > 5));// find() 获取满足条件的第一个元素//findLast() 获取满足条件的最后一个元素//findIndex()// arr.reduce()累加器console.log(arr.reduce((acc, cur)=>acc+cur));
(3) ['a', 'b', 'c'](2) ['a', 'b'](3) ['A', 'a', 'b'](2) ['a', 'b'](2) [0, 'c'](2) [1, 'd'](2) [2, 'a'](2) [3, 'b'](2) ['a', 'b']true['b'](4) [1, 3, 5, 9](4) [9, 5, 3, 1]false[9]18
function Code(nd, fe, b){this.nd = ndthis.fe = fethis.b = b}Code.prototype.show = function(){return `${this.nd}:[${this.fe}]` //以自定义格式输出}let code = new Code(28, 68, 1)console.log(code);console.log(code.show());// ES6中的类,是构造方法/*** 内部成员间没有,* 必须用简写*/class Grade{constructor(br, hcj){this.br = brthis.hcj = hcj}show(){return `${this.br}:${this.hcj}`}// 静态成员static company = 'dmegc'}// 访问const N48H = new Grade(13.6, 17)console.log(N48H);console.log(N48H.show());console.log(Grade.company);// 静态成员let f = function(){}f.a = 'hello'console.log(f.a);class Formula extends Grade{constructor(br, hcj, d){super(br,hcj)this.d = d}/*** 可以引入访问器,同名时访问器属性大于原始属性*/show(){return `${super.show()}, ${this.d}`}}const N48H01 = new Formula(13.6, 17, 7.5)console.log(N48H01.show());N48H01.d = 7.55console.log(N48H01.show());
Code {nd: 28, fe: 68, b: 1}28:[68]Grade {br: 13.6, hcj: 17}13.6:17dmegchello13.6:17, 7.513.6:17, 7.55
进入js需要练习的东西多了,class要好好联系一下,用好了处理数据很有用的,目前最头疼的是众多数据如何设计数据表。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号