0

I am getting a syntax error on the following code for the line where I define the object within the for loop. What is going wrong here?

var NAMES     = [ 'Accessories', 'Basins' ];      
var VARIANTS  = [ ['red','green','blue'], ['red','green','blue'] ];  
var numGroups = AD_GROUP_NAMES.length;
var INFO      = [];

for (var x = 0; x =< numGroups; x++) {
    var obj = { name : NAMES[x], variants : VARIANTS[x] };
    INFO.push(obj);
}

Any ideas? Any help appreciated.

4
  • 5
    x =<numGroups should be x <=numGroups Commented Apr 28, 2017 at 11:16
  • Where is AD_GROUP_NAMES defined? Commented Apr 28, 2017 at 11:19
  • array traversal for loop : for(var i = 0 ; i < arr.length ; i++) Commented Apr 28, 2017 at 11:19
  • what result do you expect? Commented Apr 28, 2017 at 11:20

1 Answer 1

1

Change comparison operator from =< to >=.

Also you should set numGroups to length - 1: var numGroups = AD_GROUP_NAMES.length - 1;

var NAMES     = [ 'Accessories', 'Basins' ];      
var VARIANTS  = [ ['red','green','blue'], ['red','green','blue'] ];  
var numGroups = 1 ;//AD_GROUP_NAMES.length - 1;
var INFO      = [];

for (var x = 0; x <= numGroups; x++) {
    var obj = { name : NAMES[x], variants : VARIANTS[x] };
    INFO.push(obj);
}

console.log(INFO);

Javascript comparison operators: https://www.ecma-international.org/ecma-262/5.1/#sec-11.8.3

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

2 Comments

Please don't reference w3schools, use either ECMA-262 or MDN.
@RobG ok, I changed the reference

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.