<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
var obj = {
name:‘whjj‘,
sex:‘nan‘,
age:28
}
obj.wight = 60//增
obj.uu
delete obj.sex //删
obj.name = "whl"//改
console.log("name" in obj)//true
console.log("uu" in obj)//false
console.log("wight" in obj)//false
console.log("toString" in obj)// 原型链上属性 true
console.log(obj.hasOwnProperty(‘wight‘)) //true
console.log(obj.hasOwnProperty(‘toString‘)) // 原型链上属性 false
for(var key in obj){
//if(arr.hasOwnProperty(key))
console.log(key); //键名
console.log(obj[key]); //键值
}
console.log(Object.keys(obj)) //["name", "age", "wight"]
console.log(Object.values(obj)) //["whl", 28, 60]
// console.log(obj)
</script>
</body>
</html>
原文:https://www.cnblogs.com/whlBooK/p/10839743.html