javaScript adding array to another array

Hi javascipt gurus,

I have a issue that is getting me frustrated I a large arrays of profiles. So I take the necessary arrays out of profile and add them to an small array called items. Then I want to take elements out of the new items array and place the string values into a select array the issue is the default if in the last for loop it will not work it only ever returns the entire string/ array. Any help would be great.


var select =[];

var profile = [];
profile["0"] = ['240','1','4','1','1','1','2.40','CR240'];
profile["1"] = ['360','3','5','1','1','1','3.60','CR360'];
profile["2"] = ['480','4','6','1','1','1','4.80','CR480'];

var items[];
var x= 0;
	
	for(var i=0;i<profile.length;i++){
		

		if(profile[i][2] == itemVar){
			
			 items[x]= hc_styleprofile[i];
			 
		x++;
		}

	}

alert(item[0]);

var defaultItem = 2;

	for(var i=0;i<item.length;i++){
		alert(item[i]);
		if(defaultItem == item[i]){
			select["default_size"]=items[i];
			select['default_size']);


		}
	
	}


look up info on forEach Object

only got it to work for firefox…

let me know if it helps…

I am sure this a typo:

select['default_size']);

You also have item & items variables - same?

Here is a cleaned up version of the code you provided:


var select = [],
	profile = [],
	items = [],
	defaultItem = 2,
	x = 0,
	i;

profile["0"] = ['240','1','4','1','1','1','2.40','CR240'];
profile["1"] = ['360','3','5','1','1','1','3.60','CR360'];
profile["2"] = ['480','4','6','1','1','1','4.80','CR480'];

// Not defined in the code provided
var itemVar, hc_styleprofile;

for(i = 0; i < profile.length; i++) {
	if(profile[i][2] === itemVar) {
		items[x] = hc_styleprofile[i];
		x++;
	}
}

// Item is not defined....
var item = [];

alert(item[0]);
for(i = 0; i < item.length; i++) {
	alert(item[i]);
	if(defaultItem === item[i]) {
		select["default_size"] = items[i];
	//  Typo?
	//	select['default_size']);
	}
}

I believe the last section should have all items and not item/s:


for(i = 0; i < items.length; i++) {
	if(defaultItem === items[i]) {
		select["default_size"] = items[i];
	}
}