一:判断对象是否具备对应的属性(key in 对象)
let aa={a:1,b:2}; let r="a" in aa; console.log(r);
true
二:Object.keys 返回一个所有元素为字符串的数组,其元素来自于从给定的 object 上面可直接枚举的属性。这些属性的顺序与手动遍历该对象属性时的一致。
例子
// simple array
var arr = ['a', 'b', 'c'];
console.log(Object.keys(arr)); // console: ['0', '1', '2']
function testAwait(){
return new Promise((resolve) => {
setTimeout(function(){
console.log(“testAwait”);
resolve();
}, 1000);
});
}
1.Promise 方式写法:
testAwait().then(()=>{
alert(1);
})
2.async/await 方式写法
async function helloAsync(){
await testAwait();
console.log(“helloAsync”);
}
helloAsync();