day1011
let person = new Object();
person.name = ‘wangyan’;
person.age = ‘20’
console.log(person.name);
//對象自變量
let person1 = {};
let s = ‘’;//模板字符串
// let s = ’
//
//
hahaha
//
// ';
name: ‘xiaoming’;
age: ‘21’;
let person2 = {
name: ‘xiaoming’,
age: ‘21’,
};
console.log(person2.name);
console.log(typeof person2); //返回值是Object
//定義數組
const oArray = new Array();//構造器構造數組
const oArray = [];
console.log(typeof oArray);
//數組初始化
const heroes = [];
console.log(heroes[0]);
heroes[0] = ‘蝙蝠俠’;
heroes[1] = ‘神奇女俠’;
heroes[2] = ‘閃電俠’;
heroes[5] = ‘水行俠’
console.log(heroes);
//數組字面量
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
console.log(avengers);
delete avengers[0];
console.log(avengers);
let person2 = {
name:“wangyan”,
age:49,
};
const a = [0,undefined,‘123223’,null,person2];
console.log(a);
//結構語法
const array1 = [1,2,3];
let a = array1[0];
let b = array1[1];
let c = array1[2];
const [a,b,c] = [1,2,3];
console.log(‘a=a,b={a},b=a,b={b},c=${c}’) //模板字符串
const [a,b] = [1,2,3];
console.log(a);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
console.log(avengers.length);
avengers.length = 1;
console.log(avengers);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
avengers.pop();//刪除末尾元素
console.log(avengers);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
avengers.pop();//刪除末尾元素
console.log(avengers);
avengers.push(‘蜘蛛俠’);//在末尾增加一個元素
console.log(avengers);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
console.log(avengers.shift());//刪除數組中的第一個元素
console.log(avengers);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
console.log(avengers.unshift(‘小超人’));//在數組的第一個元素前添加一個元素
console.log(avengers);
//數組的合并
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const heroes = [‘美國隊長’,‘雷神’,‘宙斯’,‘雅典娜’]
const oArray = avengers.concat(heroes);
console.log(avengers);
console.log(oArray);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const heroes = [‘美國隊長’,‘雷神’,‘宙斯’,‘雅典娜’]
const oArray = […avengers,…heroes];
console.log(oArray);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const a = avengers.join(’&’);
console.log(a);
console.log(avengers);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const b = avengers.slice(2,3);
console.log(b);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const c = avengers.splice(2,2,‘xiaoming’,2,3);
console.log?;
console.log(avengers);
const d = [‘a’,‘b’,‘c’,‘d’]
const e = d.reverse();
console.log(e,d);
const f = [‘1’,‘2’,‘10’,‘6’]
const g = f.sort();
console.log(g,f);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const a1 = avengers.indexOf(‘神奇隊長1’);
console.log(a1);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const a2 = avengers.includes(‘神奇隊長’);
console.log(a2);
const avengers = [‘蝙蝠俠’,‘神奇女俠’,‘閃電俠’,‘水行俠’]
const a3= avengers.includes(‘神奇女俠’);
console.log(a3);
//多維數組
const ma = [[1,2],[3,4]];
console.log(ma[0][0])
const sumer = [‘jul’,‘ghi’,‘jan’];
const winter = [‘jul’,‘koj’,‘fil’];
const spring = [‘jan’,‘jku’,‘til’];
const flat = [sumer,winter,spring];
console.log(flat);
//set
const list = new Set();
list.add(1);
list.add(1),add(2),add(3),add(4),add(5);
list.add(5)
console.log(list);
const list = new Set([1,2,3,4,5])
console.log(list);
//數組去重
const a = [1,2,12,1,2,3,4,5]
const b = new Set(a);
console.log(b);
const c = […b];
console.log?;
const list = new Set([1,2,3,4,5])
console.log(list);
const c = new Set(‘Hello’)
console.log?
const list4 = new Set().add(‘the’).add(‘quick’).add(‘brown’).add(‘fox’);
console.log(list4);
const list4 = new Set().add(‘the’).add(‘quick’).add(‘brown’).add(‘fox’);
console.log(list4.size);
list4.size = 6;
console.log(list4.has(‘brow’));
const list4 = new Set().add(‘the’).add(‘quick’).add(‘brown’).add(‘fox’);
console.log(list4.size);
list4.size = 6;
console.log(list4);
const list4 = new Set().add(‘the’).add(‘quick’).add(‘brown’).add(‘fox’);
console.log(list4.has(‘brow’));
list4.delete(‘the’);
console.log(list4)
list4.clear();
console.log(list4);
const list4 = new Set().add(‘the’).add(‘quick’).add(‘brown’).add(‘fox’);
const oArray = […list4];
console.log(oArray);
const list4 = new Set().add(‘the’).add(‘quick’).add(‘brown’).add(‘fox’);
const oArray = Array.from(list4);
console.log(oArray);
// 內存泄漏
let array1 = [1, 2, 3];
let array2 = [3, 4, 5];
const strong = new Set().add(array1).add(array2);
console.log(strong.has(array1));
array1 = null; // 刪除對原始對象的引用
array2 = null;
array3 = […strong][0];
array4 = […strong][1];
console.log(array3);
console.log(array4);
let array1 = [1, 2, 3];
let array2 = [3, 4, 5];
const weak = new WeakSet().add(array1).add(array2);
console.log(weak);
array1 = null;
array2 = null;
const array3 = […weak][0];
const array4 = […weak][1];
console.log(array3);
console.log(array4);
//map
const romanNumerals = new Map();
romanNumerals.set(1,‘一’);
romanNumerals.set(2,‘二’).set(3,‘三’).set(4,‘四’).set(5,‘五’);
console.log(romanNumerals);
console.log(romanNumerals.size);
console.log(romanNumerals.get(3));
console.log(romanNumerals.has(5));
romanNumerals.delete(5);
console.log(romanNumerals);
romanNumerals.clear();
console.log(romanNumerals);
// map to array
const romanNumerals = new Map();
romanNumerals.set(1,‘一’).set(2,‘二’).set(3,‘三’).set(4,‘四’).set(5,‘五’);
const oArray1 = […romanNumerals];
const oArray2 = Array.from(romanNumerals);
console.log(oArray1);
console.log(oArray2);
//review
/*
數據類型
基礎類型:String、Number Boolean Symbol undefined null
引用類型:Object/Function
兩種:
對象構造函數
let oStudent = new Object();
對象字面量
let oStudent = {
name: ‘xaaaa’,
age: 21
}
oStudent.name
Array
new Array()
[]
Set
let oSet = new Set();
oSet.add(1).add(2)
let oSet = new Set([1,2,3]);
*/
總結
- 上一篇: excel shell合成_shell快
- 下一篇: 终于搞定美团app人气榜提取的数据分类工