JSFiddle - React, Tailwind, and code Playground

JavaScript

// Data contains objects that each have an array of images.
// I want only the first image of each object.
var data1 = [
	{
  	id: 1,
    images: [
    	{ name: '1a' },
      { name: '1b' }
    ]
  },
  {
  	id: 2,
    images: [
    	{ name: '2a' },
      { name: '2b' }
    ]
  },
  {
  	id: 3
  },
  {
  	id: 4,
    images: []
  }
];

function* foo(g){
  
  for (let i=0;i<g.length;i++) {
 
  if (g[i]['images'] && g[i]["images"].length  )
    yield g[i]['images'][0]["name"];
    }
}

    var iterator = foo(data1) ;
    var result = iterator.next();
 
     while (!result.done)
    {
        console.log(result.value)
        result = iterator.next();
    }
 



// How can I make this prettier?