对象 Object

| 检查属性是否在对象上

hasOwnProperty() 函数用于指示一个对象自身(不包括原型链)是否具有指定名称的属性。 如果有,返回 true,否则返回 false

var myObject = {
  name: '@tips_js',
}
myObject.hasOwnProperty('name') // true
'name' in myObject // true
myObject.hasOwnProperty('valueOf') // false, valueOf is inherited from the prototype chain
'valueOf' in myObject // true

| 剩余参数

const { a, b, ...z } = { a: 1, b: 2, c: 3, d: 4 }
console.log(a) // 1
console.log(b) // 2
console.log(z) // { c: 3, d: 4 }

| 判断对象是否为空

Object.keys(obj).length

| 合并多个对象

const user = {
  name: 'John Ludwig',
  gender: 'Male',
}

const college = {
  primary: 'Mani Primary School',
  secondary: 'Lass Secondary School',
  test: '2',
}
const skills = {
  programming: 'Extreme',
  swimming: 'Average',
  sleeping: 'Pro',
  test: '3',
}

const summary = { ...user, ...college, ...skills }

// 若有相同属性,后一个对象的属性值会覆盖前一个对象的属性值
// {
//   gender: "Male"
//   name: "John Ludwig"
//   primary: "Mani Primary School"
//   programming: "Extreme"
//   secondary: "Lass Secondary School"
//   sleeping: "Pro"
//   swimming: "Average"
//   test: "3"
// }