[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

Can somebody give me an example how I can call this forEachIn function

Tony Johansson

1/10/2015 2:22:00 PM

Just specify some variables or object so I can uderstand hiw this forEachIn
can be called

function forEachIn(object, action)
{
for(var property in object)
{
if (object.hasOwnProperty(property))
{
action(property, object[property]);
}
}
}

//Tony

2 Answers

Martin Honnen

1/11/2015 2:58:00 PM

0

Tony Johansson wrote:
> Just specify some variables or object so I can uderstand hiw this
> forEachIn can be called
>
> function forEachIn(object, action)
> {
> for(var property in object)
> {
> if (object.hasOwnProperty(property))
> {
> action(property, object[property]);
> }
> }
> }

For instance,

var obj = { prop1: 'foo', prop2: 42 };

forEachIn(obj, function(propName, propValue) {
console.log(propName + ' has value "' + propValue + '"');
});

will output

prop1 has value "foo"
prop2 has value "42"


--- news://freenews.netfront.net/ - complaints: news@netfront.net ---

Thomas 'PointedEars' Lahn

1/11/2015 4:44:00 PM

0

Martin Honnen wrote:

> Tony Johansson wrote:
>> function forEachIn(object, action)
>> {
>> for(var property in object)
>> {
>> if (object.hasOwnProperty(property))
>> {
>> action(property, object[property]);
>> }
>> }
>> }
>
> For instance,
>
> var obj = { prop1: 'foo', prop2: 42 };
>
> forEachIn(obj, function(propName, propValue) {
> console.log(propName + ' has value "' + propValue + '"');
> });
>
> will output
>
> prop1 has value "foo"
> prop2 has value "42"

The for-in iteration order is not defined, so the lines above could be
reversed.

> --- news://freenews.netfront.net/ - complaints: news@netfront.net ---

I strongly suggest not to use that service, it is a major source of trolls.

--
PointedEars
FAQ: <http://PointedEars.... | SVN: <http://PointedEars.de...
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-...
Please do not cc me. / Bitte keine Kopien per E-Mail.