Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hello everyone,
I am new to javascript and I want to store different type of values for objects.
How can I store more than one title.usr for different objects like person[0] etc

JavaScript
var title=new Array();
   person.usr=titleValue;
   person.pass=pass;


for many persons
Posted

1 solution

You need to understand that person.usr is exactly the same as person["usr"]. Arrays and other objects are pretty much the same thing: associative container. Perhaps the only difference for array is its predefined property length.

It's weird that you want to store titles in the array. You should better store the objects themselves:
JavaScript
var array = [

	{title: "Mr", pass: "I won't tell you"},
	{title: "Mrs", pass: "Get lost!"},
	{species: "Turdus migratorius", genus: "Turdus",
		family: "Turdidae",
		conservationStatus: "least concern"}

];

var someProperty = array[2].family;
   // defined for one array element,
   //not for another one

Any questions?
Javascript is said to be the most misunderstood language of all times. Please see:
http://davidwalsh.name/javascript-objects-distractions[^].

—SA
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900