in the other programming languages we use &
keyword for passing variable by reference.
for example, in php;
$a = 10;
function something(&$a){
$a = 7;
};
something($a);
echo $a;
// 7
How can we do this in javascript ?
When user click the right or left arrow, I'm trying to get next or prev. image by array index;
list: function (index) {
let items = this.images;
return {
next: function () {
if (index > items.length -1) {
index = 0;
}
return items[index++];
},
prev: function () {
if (index < 0) {
index = items.length -1;
}
return items[index--];
}
}
}
Outside of this iterator, I need to use index variable. But I only get old value... I want to get current index.