0

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];
          }
        }
      }
    }
3
  • selCOption2[i]['labelname'] = selOption2Arr[i]; Commented Nov 21, 2014 at 16:54
  • 2
    This is valid syntax, but not a sensible thing to do. The expression "i, 'labelname'" is a comma operator expression, and the effect is no different from selCOption2['labelname'] = ... (except for the highly unusual case where there might be a getter function on i, which is not the case here). Commented Nov 21, 2014 at 16:55
  • …and so what you have is equivalent with selCOption2['labelname'] = selOption2Arr[i];. Commented Nov 21, 2014 at 16:56

1 Answer 1

4

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.