/    Sign up×
Community /Pin to ProfileBookmark

pass variable by reference instead of a copy of variable

not sure if this is possible, but…in PHP i can pass a reference to a variable instead of passing a copy of that variable by changing adding an ampersand before the variable name like so… &$variable …is there an equivalent in JavaScript? I have a rather bloated array that i’d like to just pass a reference to and avoid using anymore resources than necessary…

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@phpnoviceJun 17.2006 — In JavaScript, objects are passed only by reference. An Array is an object.

var temp = new Array(0, 2, 3);

alert(temp);

function updateit(ary) { ary[0] = 1; }

updateit(temp);

alert(temp);
Copy linkTweet thisAlerts:
@bcamp1973authorJun 17.2006 — awesome thanks!
Copy linkTweet thisAlerts:
@phpnoviceJun 18.2006 — You're welcome.

Cheers.
×

Success!

Help @bcamp1973 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.16,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

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