let data ={ a:'a', b:'b', c:'c', d:'d', e:'e'}// break 跳出switch循环,但是for循环继续// no a => b => no c => no d => no efor(key in data){switch(key){case"b":
console.log(key);break;default:
console.log('no', key);}}// label语句 当满足条件后跳出for循环// no a => b
outloop:for(key in data){switch(key){case"b":
console.log(key);break outloop;default:
console.log('no', key);}}
width 将作用域设置到特定的对象中
a ='AAA';
b ='BBB';let data ={ a:'aaa'}with(data){
console.log(a);// aaa
console.log(b);// BBB}
JSON stringify
var foo ={ name:"Lee", age:24, sex:'男'};var jsonString =JSON.stringify(foo,(key, value)=>{
console.log(key, value);// name Lee --- age 24 --- sex 男if(typeof value ==='number'){return undefined
}return value
});
console.log(jsonString);// {"name":"Lee","sex":"男"}const students =[{
name:'akira',
score:100,},{
name:'John',
score:60,},{
name:'Jane',
score:90,}];let jsonStudents =JSON.stringify(students,(key, value)=>{if(key ==='score'){if(value ===100){return'S';}elseif(value >=90){return'A';}elseif(value >=70){return'B';}elseif(value >=50){return'C';}else{return'E';}}return value;});
console.log(jsonStudents);// [{"name": "akira","score": "S"},{"name": "John","score": "C"},{"name": "Jane","score": "A"}]let jsonStudentsNames =JSON.stringify(students,['name']);
console.log(jsonStudentsNames);// [{"name":"akira"},{"name":"John"},{"name":"Jane"}]