Parse user data in to student and teacher details Initially I have a code in JavaScript which looks like -
const createUsersInfo = obj =&gt; {
    const studentDetails = [];
    const teacherDetails = [];
    obj.forEach(x =&gt; {
      if (x.type) {
        if ( x.type === 'teacher' &amp;&amp; x.group !== 'admin' ) {
            teacherDetails.push(x);
        } else if ( x.type === 'student' &amp;&amp; x.group !== 'admin' ) {
            studentDetails.push(x);
        }
      }
    });

    return {
        studentDetails,
        teacherDetails
    };
};

Then, I refactored it to -
const createUsersInfo = obj =&gt; {
  const studentDetails = [];
  const teacherDetails = [];
  obj.forEach(x =&gt; {
    const type = x.type;
    if ( type &amp;&amp; x.group !== 'admin' ) {
      if ( type === 'teacher' ) {
        teacherDetails.push(x);
      }
      if ( type === 'student' ) {
        studentDetails.push(x);
      }
    }
  });

  return {
    studentDetails,
    teacherDetails
  };
};

Is this better as compared to my initial version or it can  further improved ?
Thanks.
A short review;

You can avoid process typeless and admin users by using an upfront .filter()
obj is a terrible name (it implies the parameter is just an Object instead of an Array, list would be better, something meaningful like userDetails the best
If you want to go for slightly less efficient code, you could replace the whole loop with 2 filters
Dont go for fat arrow syntax unless you are coding and inline function

I would go for something like this;
function createUsersInfo(userDetails){
  const cleanUserDetails = userDetails.filter(user =&gt; (user.type &amp;&amp; user.group != 'admin'));
  return {
    studentDetails: cleanUserDetails.filter(user =&gt; user.type === 'student'),
    teacherDetails: cleanUserDetails.filter(user =&gt; user.type === 'teacher')
  };
}