I was wondering how can I create a JSON (JS) object and then clone it.
I was wondering how can I create a JSON (JS) object and then clone it.
How to create a JSON object in javascript/jquery?
There is nothing like a JSON object. JSON stands for JavaScript Object Notation and is basically a string that encodes information similar to JavaScript's object literals.
You can however create such an encoding (which would result in a string) with JSON.stringify(object)
, see JSON in JavaScript. You could also create such a string manually, but it is very error prone and I don't recommend it.
How do I clone a JSON object in javascript/jquery?
As it is just a string:
var jsonString2 = jsonString;
I can`t work anymore with javascript arrays
JSON is a format to exchange data, it is not a data structure you can use in an application.
Maybe you want to read more about JSON, objects in JS and arrays in JS.