How do you identify an object by its place in the object.
myObj.b = 2
can I go somethiong like myObj[1] to show 2 also?
var myObj = {
a: 1,
b: 2,
c: 3,
d: 4,
e: 5,
f: 6
}
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
No, this is not possible. An object property has no position as objects are not ordered.
You have to choose between:
[0..length), in order.A possible workaround would be creating both an object and an array and then using the object for key-based access and the array for index-based. You could then use the array to get the index(es) for a given value.