CodesJava

Easy learning with example program codes

Object.assign() JavaScript

The Javascript Object assign() method copies enumerable and own properties from a source object to a target object. The whole operation (assignment and copy) is done by reference.

Syntax:

Object.assign(target, sources) 

Parameters:
target: It represents the target object.
source: It represents the source object.

Return:
It returns the target object.

Example:

<!DOCTYPE html>
<html>
<body>
<script>
const first = {x: 1, y: 2, z: 3};  
const second = Object.assign({x: 3, z: 4, w: 5}, first);  
document.write(second.z + "</br>");
document.write(second.w + "</br>");
document.write(second.x);
</script>
</body>
</html>

Output:

3
5
1
Please follow and like us:
error








Copyright © 2019 CodesJava DMCA.com Protection Status