Understanding es6 fetch returning and transforming promise data

Understanding es6 fetch returning and transforming promise data
0

#1

I’m new to es6 and trying to wrap my head around the new fetch api. When I try and access firstNames variable I get undefined although the promise has been resolved.

const url = 'https://jsonplaceholder.typicode.com/users/';

function get(url) {
  return fetch(url)
    .then(response => response.json());
}

const users = function users() {
  return get(url)
    .then(data => data);
};

const firstNames = users().then((user) => {
  return user.map((user) => {
    return user.name.split(' ')[0];
  });
});