| 
	
	
		
		
			
			 
				Создание из 2 массивов массив объектов
			 
			
		
		
		
		Здравствуйте, Всем! 
 
Помогите, пожалуйста разобраться. Обыскался уже... 
 
Есть задача объединить два массива в объект массивов.  
 
var positions = [ 
  'Bosh VZHIH-101', 
  'Ariston WHO-D', 
  'Atlant Mattel 2016', 
  'Wirpool FLASH black edition', 
  'Bosh VH1Z-024' 
]; 
 
var prices = [ 
  10000, 
  4800, 
  9200, 
  2500, 
  5700 
]; 
 
На выходе нужно получить: 
[ { name: 'Bosh VZHIH-101', price:10000}, 
  { name:  'Ariston WHO-D', price:4800}, 
  { name: 'Atlant Mattel 2016', price:9200 }, 
  { name: 'Wirpool FLASH black edition', price:9200 }, 
  { name: 'Bosh VH1Z-024', price:5700} ] 
 
 
У меня же получается:  
[ { name: 'Bosh VZHIH-101' }, 
  { name: 'Ariston WHO-D' }, 
  { name: 'Atlant Mattel 2016' }, 
  { name: 'Wirpool FLASH black edition' }, 
  { name: 'Bosh VH1Z-024' }, 
  { price: 10000 }, 
  { price: 4800 }, 
  { price: 9200 }, 
  { price: 2500 }, 
  { price: 5700 } ] 
 
 
Мой код: 
 
'use strict'; 
 
var positions = [ 
  'Bosh VZHIH-101', 
  'Ariston WHO-D', 
  'Atlant Mattel 2016', 
  'Wirpool FLASH black edition', 
  'Bosh VH1Z-024' 
]; 
 
var prices = [ 
  10000, 
  4800, 
  9200, 
  2500, 
  5700 
]; 
 
 
var hits = []; 
 
function createObj(arrayName) { 
   
     
  return arrayName.forEach(function(index){ 
      var hash = {}; 
      if (arrayName == positions){ 
      hash.name = index; 
      } else { 
      hash.price = index; 
      } 
       
      hits.push(hash); 
        
    }); 
 
} 
 
createObj (positions); 
createObj (prices); 
hits; 
 
Подправьте, пожалуйста. 
		
	
		
		
		
		
		
		
	
		
			
			
	
			
			
			
			
			
				 
			
			
			
			
			
			
				
			
			
			
		 
		
	
	
	 |