question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Duplicating an data object

See original GitHub issue

Hello, in order to duplicate an object with all its children, I had to use a jQuery function, please is there a better way in Vue? I am using Vue 0.12.1

duplicateThis: function (field) {
    var currentField = this.fields[field.index];

    var insertField = {
        name: currentField.name,
        type: currentField.type,
        description: currentField.description,
        options: $.extend(true, {}, currentField.options),
        required: currentField.required
    };

    this.fields.splice(field.index + 1, 0, insertField);
}

Thank you

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:19 (1 by maintainers)

github_iconTop GitHub Comments

80reactions
nirazulcommented, Jun 25, 2015

Have you tried JSON.parse(JSON.stringify(field))?

67reactions
rikardocorpcommented, Sep 2, 2017

var obj = { a: 1 }; var copy = Object.assign({}, obj); console.log(copy); // { a: 1 }

Read more comments on GitHub >

github_iconTop Results From Across the Web

3 Ways to Clone Objects in JavaScript | SamanthaMing.com
# 1. Using Spread ... Using spread will clone your object. Note this will be a shallow copy. As of this post, the...
Read more >
Object copying - Wikipedia
In object-oriented programming, object copying is creating a copy of an existing object, a unit of data in object-oriented programming. The resulting object...
Read more >
Duplicating Objects - Foundry Learn
You can duplicate child objects but not parent objects, locators, or child locators. Duplicating an object creates a copy of it and adds...
Read more >
How to copy objects in JavaScript: A complete guide
A complete guide to copying objects in JavaScript: shallow copy, deep copy, assigning, merging, and structured cloning.
Read more >
Create Duplicate Object (CRTDUPOBJ) - IBM
The Create Duplicate Object (CRTDUPOBJ) command copies a single object or a group of objects. It does not create an exact duplicate of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found