/    Sign up×
Community /Pin to ProfileBookmark

Can I get unknown parameters count in function?

I want to do function which get values and send them whith ajax

function sendArray(values*)
{
var result;
for(i=0;i<values.length;i++)result+=values[i]+”&”;
result=result.substr(0,result.length-1);
sendHttpRequest(result);
}

example:
sendArray(‘a=1′,’b=2′,’c=4’);

It is possible?

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jun 07.2006 — You need to use the arguments array. Example here: http://www.devguru.com/Technologies/ecmascript/quickref/arguments.html

Eric
Copy linkTweet thisAlerts:
@nadavvinauthorJun 07.2006 — thanks
Copy linkTweet thisAlerts:
@KorJun 07.2006 — If I well understood your aim... You may pass an object (or an array, but an object is easy to construct/de-construct), something like this:
<i>
</i>&lt;script type="text/javascript"&gt;
function sendObj(obj){
var query=''
for(arg in obj){
query+=arg+'u003d'+obj[arg]+'u0026'
}
query=query.replace(/&amp;$/,'');
alert(query)
}
onload=function(){
var obj={a:1,b:2,c:3}
sendObj(obj)
}
&lt;/script&gt;
×

Success!

Help @nadavvin spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.11,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,
)...