Creates a shallow clone of `value`. **Note:** This method is loosely based on the [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) and supports cloning arrays, array buffers, booleans, date objects, maps, numbers, `Object` objects, regexes, sets, strings, symbols, and typed arrays. The own enumerable properties of `arguments` objects are cloned as plain objects. An empty object is returned for uncloneable values such as error objects, functions, DOM nodes, and WeakMaps.
const objects = [{ 'a': 1 }, { 'b': 2 }]
const shallow = clone(objects)
console.log(shallow[0] === objects[0])
// => true
| Name | Type | Attribute | Description |
|---|---|---|---|
| value | The value to clone. |
*
{
"comment": "/**\r\n * Creates a shallow clone of `value`.\r\n *\r\n * **Note:** This method is loosely based on the\r\n * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)\r\n * and supports cloning arrays, array buffers, booleans, date objects, maps,\r\n * numbers, `Object` objects, regexes, sets, strings, symbols, and typed\r\n * arrays. The own enumerable properties of `arguments` objects are cloned\r\n * as plain objects. An empty object is returned for uncloneable values such\r\n * as error objects, functions, DOM nodes, and WeakMaps.\r\n *\r\n * @since 0.1.0\r\n * @category Lang\r\n * @param {*} value The value to clone.\r\n * @returns {*} Returns the cloned value.\r\n * @see cloneDeep\r\n * @example\r\n *\r\n * const objects = [{ 'a': 1 }, { 'b': 2 }]\r\n *\r\n * const shallow = clone(objects)\r\n * console.log(shallow[0] === objects[0])\r\n * // => true\r\n */",
"meta": {
"range": [
976,
1049
],
"filename": "clone.js",
"lineno": 30,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100000577",
"name": "clone",
"type": "FunctionDeclaration",
"paramnames": [
"value"
]
}
},
"description": "Creates a shallow clone of `value`.\r\r**Note:** This method is loosely based on the\r[structured clone algorithm](https://mdn.io/Structured_clone_algorithm)\rand supports cloning arrays, array buffers, booleans, date objects, maps,\rnumbers, `Object` objects, regexes, sets, strings, symbols, and typed\rarrays. The own enumerable properties of `arguments` objects are cloned\ras plain objects. An empty object is returned for uncloneable values such\ras error objects, functions, DOM nodes, and WeakMaps.",
"since": "0.1.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Lang",
"value": "Lang"
}
],
"params": [
{
"type": {
"names": [
"*"
]
},
"description": "The value to clone.",
"name": "value"
}
],
"returns": [
{
"type": {
"names": [
"*"
]
},
"description": "Returns the cloned value."
}
],
"see": [
"cloneDeep"
],
"examples": [
"const objects = [{ 'a': 1 }, { 'b': 2 }]\r\rconst shallow = clone(objects)\rconsole.log(shallow[0] === objects[0])\r// => true"
],
"name": "clone",
"longname": "clone",
"kind": "function",
"scope": "global",
"___id": "T000002R000060",
"___s": true,
"filepath": "clone.js"
}