如何存储具有多个值的对象数组 [英] How do I store array of object with many values
本文介绍了如何存储具有多个值的对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
我是javascript的新手,我想为对象存储不同类型的值。
如何为不同的对象存储多个title.usr,如person [0]等
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
var title=new Array();
person.usr=titleValue;
person.pass=pass;
适合很多人
for many persons
推荐答案
你需要了解person.usr
与person [usr]
完全相同。数组和其他对象几乎完全相同: 关联容器 。也许数组的唯一区别是它的预定义属性length
。
你想要存储标题很奇怪数组。您最好自己存储对象:
You need to understand thatperson.usr
is exactly the same asperson["usr"]
. Arrays and other objects are pretty much the same thing: associative container. Perhaps the only difference for array is its predefined propertylength
.
It's weird that you want to store titles in the array. You should better store the objects themselves:
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
有问题吗?
Javascript据说是有史以来最容易被误解的语言。请参阅:
http://davidwalsh.name/javascript-objects-distractions [< a href =http://davidwalsh.name/javascript-objects-distractionstarget =_ blanktitle =New Window> ^ ]。
这篇关于如何存储具有多个值的对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文