0

To be more specific, I need to essentially create an object where I can store and read values.

I'm a bit of a noob in JS, so I'm sorry if my understanding is limited. I'll give an example.

var usrobj = mainobj.id(userIDHere);
var usrplays = usrobj.plays;

Stuff like that.

But, I also would need to write to the plays value. Any ideas?? (I don't know a crap ton about JavaScript, compared to most of you)

9
  • 3
    Come to the JavaScript room, we'll make you a pro in no time! (You just need 20 rep) Commented Apr 23, 2014 at 22:40
  • 2
    MDN's Working With Objects article. Or any half-decent JS tutorial. Commented Apr 23, 2014 at 22:41
  • 2
    reason for down vote: this question's answer is obviously somewhere that google can find on the internet. Commented Apr 23, 2014 at 22:41
  • var someObject = {}; // hey, it's an object! Commented Apr 23, 2014 at 22:42
  • 1
    @adrichman this question has never been questioned on SO, and the purpose of SO is to answer all of the programming questions immaginable, and SO wants to be at the top list of google searches, but how can it if it has no object declaration question? So I'd consider upvoting so he can enter the js room and we can help him out with all of the basic needs of a new Javascripter() Commented Apr 23, 2014 at 22:52

1 Answer 1

2

Objects are really awesome in js because they are so simple. You can create an object as simply as:

var usrobj = {};

That is all you need. You can then add keys to it as easily as:

userobj.plays = somevalue;

And then read from it as easily as:

console.log(userobj.plays);

Hope that helps.

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

2 Comments

Yknow what. I feel like an idiot right now. xD Thank you. <3
@WesleyBellah come in the js chat anyway, we can teach you much more than this. remember this thing and click it when you have at least 20 reputation

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.