0

Can I:

  1. Get JS object properties as array?
  2. Get property by name (like obj.prop('propname').val())
  3. Set property value by name (obj.prop('propname').val('WAT?'))
  4. Create property by name(obj.createprop('propname')).

Why I need this: I have some model declaration (with names, types and in-response ids) and want parse JSON data according to it.

Arman Hayots
  • 2,459
  • 6
  • 29
  • 53
  • http://www.htmlgoodies.com/tutorials/web_graphics/object-reflection-in-javascript.html – vidriduch May 12 '15 at 10:37
  • 2
    Your other two questions are duplicates of http://stackoverflow.com/questions/11256091/how-to-access-object-property-using-variable - please try to limit yourself to one question per question. – Quentin May 12 '15 at 10:38
  • can you provide sample what you want to do? – Grundy May 12 '15 at 10:40
  • @Quentin, seems, that question can be more specific than in duplicate, if OP provide additional info – Grundy May 12 '15 at 10:40
  • I need it for this http://stackoverflow.com/questions/30187807/manually-parse-json-data-according-to-kendo-model – Arman Hayots May 12 '15 at 10:47
  • So, I'm visited «original» question, but there's no words about `get` and `set`. – Arman Hayots May 12 '15 at 10:49
  • 1
    The fact that a question is duplicate doesn't mean it's identical to yours verbatim, but instead that it asks about and explains the same concept. – Etheryte May 12 '15 at 10:55
  • @ArmanHayots js is a very dynamic language, you can create property with simple assign: `a.a = "val"` create property _a_ if it not exist. You need ask more specific question, and also provide what you tried – Grundy May 12 '15 at 10:56
  • I need create property name, which I will know only in runtime. Can I create `b` property by `a['b'] = 'val'`? – Arman Hayots May 12 '15 at 10:57
  • 1
    @ArmanHayots yep, you can, this is called [bracket notation](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Property_accessors#Bracket_notation) – Grundy May 12 '15 at 10:58

0 Answers0