Home  >  Q&A  >  body text

javascript - JSON.parse(JSON.stringify(data))

Ask when to use JSON.parse(JSON.stringify(data))

曾经蜡笔没有小新曾经蜡笔没有小新2695 days ago911

reply all(3)I'll reply

  • 欧阳克

    欧阳克2017-06-26 10:59:54

    Generally used to deep copy a json object, it can also be used to remove attributes whose values ​​do not have JSON representation (numbers, strings, logical values, arrays, objects, null), that is to say attributes like undefined and function value.

    a: {
        age: 1,
        name: undefined,
        time: () => {...}
    }
    变成:
    b: {
        age: 1
    }

    reply
    0
  • 三叔

    三叔2017-06-26 10:59:54

    Objects can be copied

    reply
    0
  • 阿神

    阿神2017-06-26 10:59:54

    Two usage scenarios:
    1. Convert JSON string to JSON object, JS direct attribute reference
    2. Clone object

    reply
    0
  • Cancelreply