← 返回博客
js2021-12-16 14:41:311 分钟 · 124 3061

js读取对象属性的方式

js中读取对象属性的两种方式

#javascript

js中读取对象属性的方式有两种

1、点方式

2、中括号方式

如果属性带有特殊符号,只能使用中括号方式读取。例如:


  var test = {
    'method':'get',
    'axios-retry':{
      lastRequestTime: 1639636666949,
      retryCount: 0,
    }
  }

  console.log(test.method)
  console.log(test['method'])
  console.log(test['axios-retry']) // axios-retry只能使用中括号方式读取


相关推荐

本文为原创文章,采用CC BY-NC-SA 4.0协议授权,转载请保留署名与原文链接。原文链接:https://www.wxbuluo.com/article/36