I've come across the following code, I'm having trouble getting my head around it.
selCOption2[i, 'labelname'] = selOption2Arr[i];
a larger excerpt
var selCOption2 = [];
var stringContent = '';
jQuery('#txtTypes').attr("value", selOption1);
for(var i=0; i<selOption2Arr.length; i++) {
if(selOption2Arr[i] != 'Plain' || selOption2Arr[i] != 'plain') {
selCOption2[i, 'labelname'] = selOption2Arr[i];
selCOption2[i, 'keyname'] = keyname+"_"+selOption2Arr[i].toLowerCase()+"_"+selOption3Arr[0].toLowerCase();
for(var ifm = 0; ifm < proJsonDetails.images.length; ifm++) {
if(proJsonDetails.images[ifm].indexOf(selCOption2[i, 'keyname']) > 0) {
selCOption2[i, 'image'] = proJsonDetails.images[ifm];
}
}
}
}
asked Nov 21, 2014 at 16:52
James Hammond
401 silver badge6 bronze badges
1 Answer 1
See a reduced test case:
var a = [ 'x', 'y', 'z' ];
var o = {};
var i = 1;
o[i, 'labelname'] = a[i];
console.log(o);
which gives:
{ labelname: 'y' }
The , operator evaluates as whatever is on the right hand side of it.
There doesn't appear to be any point in having i, in that code.
answered Nov 21, 2014 at 16:56
Quentin
949k137 gold badges1.3k silver badges1.4k bronze badges
Sign up to request clarification or add additional context in comments.
Comments
lang-js
selCOption2[i]['labelname'] = selOption2Arr[i];i, 'labelname'" is a comma operator expression, and the effect is no different fromselCOption2['labelname'] = ...(except for the highly unusual case where there might be a getter function oni, which is not the case here).selCOption2['labelname'] = selOption2Arr[i];.