[removed] Getting a Single Property Name

前端 未结 5 1678
耶瑟儿~
耶瑟儿~ 2020-12-19 20:51

Given an object like this:

{ name: \"joe\" }

I want to get the value \"name\". I know I can use the for construct to iterate over the prope

5条回答
  •  再見小時候
    2020-12-19 21:05

    Nope, iteration is the only well-supported way to get the property name. So for...in time it is. Just hide it in a function and it'll look fine.

    However, it might also be worth thinkin about whether you should be using a different kind of object for your purpose, say, {"property": "age", "value": 24}, or even ["age", 24]

提交回复
热议问题