0

I don’t know what it is called or I would look it up, but when acsessing an object or arrays element in jQuery what is the differance between Obj.element and Obj[”element”]?

3
  • They are called Object property accessors. They are the same, both try to access a property named element Commented Jul 8, 2017 at 3:43
  • Bracket notation. That's what it's called specifically. Commented Jul 8, 2017 at 3:49
  • This question is similar to: JavaScript property access: dot notation vs. brackets?. If you believe it’s different, please edit the question, make it clear how it’s different and/or how the answers on that question are not helpful for your problem. Commented Jan 16 at 14:59

1 Answer 1

1
Obj.element and Obj[”element”]

Both these will access the same key element inside object Obj. Value against key name "element" will be returned.

Sign up to request clarification or add additional context in comments.

4 Comments

@IsaacS.Weaver Well, arrays are just objects with the keys 0, 1, 2, etc. You can't do arr.0 so you do arr[0]. It's the same operation.
Note arr[0] is equivalent to arr["0"], as property names are strings (or symbols)
@IsaacS.Weaver dot notation doesn't work on arrays, although arrays are objects with keys starting from 0 and incrementing for every push operation.
Perfect that answers my question completely! Thank you all!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.