0

My object array is as follows:

{
  user_id: '2',
  imagefilename: '/data/data',
  coordinates: [ { classes_id: 2, coordinate: [Array] } ]
}

array I want to create

  {
  user_id: '2',
  imagefilename: '/data/data'
  }

how can I do it.

2 Answers 2

2

You could use destructuring:

const A = { user_id: '2', imagefilename: '/data/data', coordinates: [ { classes_id: 2, coordinate: [Array] } ] }

const { coordinates, ...B } = A;

console.log(B);

this way, any A's properties that are specified will be omitted, and the rest of the properties will be added to B. For example if you want to exclude imagefilename field as well, you could use const { coordinates, imagefilename, ...B } = A;

Sign up to request clarification or add additional context in comments.

Comments

0

let arr = [{ user_id: '2', imagefilename: '/data/data', coordinates: [ { classes_id: 2, coordinate: [Array] } ] }];

let output = arr.map(a => { return {user_id: a.user_id, imagefilename: a.imagefilename}})

console.log(output);

You could do this using the map function to solve this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.