0

I have a fake data object user that is something like this:

const user = {
    _id: String,
    name: String,
    userUploads: Array,
};

How can I make a copy of user in userOne to have something like this

const userOne = {
    _id: 'dddddd',
    name: 'Chioma',
    userUploads: [
        {
            id: 0,
            // eslint-disable-next-line max-len
            image: 'http://sugarweddings.com/files/styles/width-640/public/1.%20The%20Full%20Ankara%20Ball%20Wedding%20Gown%20@therealrhonkefella.PNG',
            reactions: {
                dislike: 0,
                like: 0,
                maybe: 0,
            },
            story: "It's my birthday next week! What do you think?",
        },
        {
            id: 1,
            // eslint-disable-next-line max-len
            image: 'https://dailymedia.com.ng/wp-content/uploads/2018/10/7915550_img20181007141132_jpeg01c125e1588ffeee95a6f121c35cd378-1.jpg',
            reactions: {
                dislike: 0,
                like: 0,
                maybe: 0,
            },
            story: 'What do you think about this?',
        },
        {
            id: 2,
            // eslint-disable-next-line max-len
            image: 'https://i0.wp.com/www.od9jastyles.com/wp-content/uploads/2018/01/ankara-styles-ankara-styles-gown-ankara-tops-ankara-gowns-ankara-styles-pictures-latest-ankara-style-2018-latest-ankara-styles-ankara-ankara-styles.png?fit=437%2C544&ssl=1',
            reactions: {
                dislike: 0,
                like: 0,
                maybe: 0,
            },
            story: 'Saturdays are for weddings. Yay or nay?',
        },
    ],
};
Giorgi Moniava
  • 27,046
  • 9
  • 53
  • 90
Ada
  • 559
  • 1
  • 3
  • 19

1 Answers1

2

You can do something like this using the spread operator:

let userOne = {...user};

But note this will be a shallow copy.

Giorgi Moniava
  • 27,046
  • 9
  • 53
  • 90