call an object property the last property passed by the object [duplicate]

Basic Idea

I propose to use the last property of the passed object for the name of returned object.
The example code below shows intended syntax.

Example Code

const users = [{
    name:'foo',
    age:25,
      company:{
        name:'companyName'
      }
  },
  {
    name:'bar',
    age:30,
      company:{
        name:'companyName2'
      }
  }];
  const companies = users.map(user=>{
    return { company: user.company, age:user.age }
  })

Example Usage

const users = [{
    name:'foo',
    age:25,
      company:{
        name:'companyName'
      }
  },
  {
    name:'bar',
    age:30,
      company:{
        name:'companyName2'
      }
  }];
  const companies = users.map(user=>{
    return { user.company, user.age }
  })

It seems like your examples work already - objects don’t have a “name”; can you elaborate on what you’d want to work differently?

We actually already have a proposal for this: GitHub - rbuckton/proposal-shorthand-improvements: A proposal to introduce new shorthand assignment forms for ECMAScript object literals

They're talking about property names:

// Before
const companies = users.map(user => {
  return { company: user.company, age:user.age };
})

// After
const companies = users.map(user => {
  return { user.company, user.age };
})
2 Likes

Sorry, I didn't find it before.

No problem! It's not well known, and the proposal hasn't been presented for some time. I'd encourage you to post on the repo to increase support.

I star and fork this repo proposal-shorthand-improvements I hope this help :)