Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #11428 > unrolled thread
| Started by | JRough <janis.rough@gmail.com> |
|---|---|
| First post | 2012-02-06 17:08 -0800 |
| Last post | 2012-02-07 13:15 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.javascript
help coding a hash table JRough <janis.rough@gmail.com> - 2012-02-06 17:08 -0800
Re: help coding a hash table Erwin Moller <erwinmollerusenet@xs4all.nl> - 2012-02-07 11:47 +0100
Re: help coding a hash table Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-02-07 13:15 +0100
| From | JRough <janis.rough@gmail.com> |
|---|---|
| Date | 2012-02-06 17:08 -0800 |
| Subject | help coding a hash table |
| Message-ID | <5cd32919-6fdd-4b39-b452-e138e0949107@lr19g2000pbb.googlegroups.com> |
How do I create a javascript associative array or a JSON object of
hours, minutes, and seconds because with code?
I think my JSON object is right but how do I create the object with 60
minutes for each hour and then 60 seconds for each minute?
Or how do I fill the array so that it is assocative?
data["hours"] =
"12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00",
"20:00","21:00","22:00","23:00","24:00",
"1:00","2:00","3:00"..."11:00"]
data["minutes"] =
"00","01","02","03","04","05","06","07","08","09","10".... "60"]
data["seconds"] =
"00","01","02","03","04","05","06","07","08","10","11"...."60"]
var oTime = [12:00, 13:00, 14:00, 15:00, 16:00, 17:00, 18:00, 19:00,
20:00, 21:00, 22:00, 23:00, 24:00 ]
};
{ data:[{ 'hours': '12:00', 'minutes':
'00','02','03','04','05','06','07','08','09','seconds:
'00','01','02','03','04','05','06','07','08' }, ]
}
Many thanks,
[toc] | [next] | [standalone]
| From | Erwin Moller <erwinmollerusenet@xs4all.nl> |
|---|---|
| Date | 2012-02-07 11:47 +0100 |
| Message-ID | <4f310138$0$6915$e4fe514c@news2.news.xs4all.nl> |
| In reply to | #11428 |
On 2/7/2012 2:08 AM, JRough wrote:
> How do I create a javascript associative array or a JSON object of
> hours, minutes, and seconds because with code?
> I think my JSON object is right but how do I create the object with 60
> minutes for each hour and then 60 seconds for each minute?
> Or how do I fill the array so that it is assocative?
> data["hours"] =
> "12:00","13:00","14:00","15:00","16:00","17:00","18:00","19:00",
> "20:00","21:00","22:00","23:00","24:00",
> "1:00","2:00","3:00"..."11:00"]
> data["minutes"] =
> "00","01","02","03","04","05","06","07","08","09","10".... "60"]
> data["seconds"] =
> "00","01","02","03","04","05","06","07","08","10","11"...."60"]
>
> var oTime = [12:00, 13:00, 14:00, 15:00, 16:00, 17:00, 18:00, 19:00,
> 20:00, 21:00, 22:00, 23:00, 24:00 ]
> };
> { data:[{ 'hours': '12:00', 'minutes':
> '00','02','03','04','05','06','07','08','09','seconds:
> '00','01','02','03','04','05','06','07','08' }, ]
> }
>
> Many thanks,
Don't.
If you must write a program that puts all integers between 0 and
1.000.000.000 on the screen, you don't write a program like this:
document.write(1);
document.write(2);
document.write(3);
......
document.write(1000000000);
Or do you?
That is why the job is called programming. You write a loop.
I cannot think of any valid reason to construct an object that holds
every hour, minute and second you can think of.
You simply store the hour, minute and second in a variable (or in 3
variables if you prefer).
There is no need to preconstruct something that holds every possible
value for a second (0 to 59).
So my advice: Rethink your problem.
About associative: If you create an empty object, just can add
"properties" with values to it to your heart's liking. That way you have
your associative array behaviour.
var myTime = new Object();
myTime.firstName = "J.";
myTime.famName = "Rough";
Regards,
Erwin Moller
--
"That which can be asserted without evidence, can be dismissed without
evidence."
-- Christopher Hitchens
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2012-02-07 13:15 +0100 |
| Message-ID | <1936201.aqSPkdTlGX@PointedEars.de> |
| In reply to | #11431 |
Erwin Moller wrote: > On 2/7/2012 2:08 AM, JRough wrote: >> How do I create a javascript associative array […] > > […] > About associative: If you create an empty object, just can add > "properties" with values to it to your heart's liking. That way you have > your associative array behaviour. > > var myTime = new Object(); > myTime.firstName = "J."; > myTime.famName = "Rough"; However, by default there are no empty objects (although there are proprietary ways like assigning to the `__proto__' property to create them, leaving a from then on crippled object). Even Object instances inherit from Object.prototype by default. As a result, some property names (like "toString") are already used. So you should avoid assigning to the corresponding properties in order to store user data. Which points out *again* _that there are no *built-in* associative arrays in ECMAScript implementations_ (but you can try to emulate them, like with jsx.map.Map [1]). PointedEars ___________ [1] <http://PointedEars.de/scripts/map.js> -- When all you know is jQuery, every problem looks $(olvable).
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web