Buy the full source code of application here:
Show More Show Less View Video Transcript
0:00
uh Hello friends welcome to this video
0:02
so in this video we will look at a
0:04
JavaScript method which is object.
0:07
assign this method allows you to copy
0:10
the properties of an object from one
0:12
object to another so this is actually
0:14
the method that we will be talking about
0:16
object. assign so this method is useful
0:20
so let's suppose you have an object
0:22
right here let me declare it obj1 and it
0:27
has some properties such as name
0:34
and then we have
0:37
age so we have these two properties in
0:40
this object
0:41
obj1 we have the name property and the
0:43
age property and uh now if I just
0:47
console of this object you will actually
0:49
see these two properties will be printed
0:52
out so now the method this is obj
0:55
assigned this method comes into the
0:57
picture if you want to transfer some
1:00
properties from one object to another so
1:02
let's suppose I declare object two and
1:05
declare some more
1:06
properties now we have name age let's
1:09
suppose we declare country as
1:13
well and then the second property
1:17
is
1:20
runs so these are two additional
1:22
properties so now if I want to transfer
1:24
these properties into the parent object
1:27
into this object this method comes to
1:30
the picture which is object. assign so
1:33
what does this method do it actually
1:36
copies the properties of the second
1:38
object to the first object so how we
1:40
actually call this method it's really
1:42
simple we simply write object do
1:46
assign and here you need to pass the
1:49
object
1:51
one in which the properties need to be
1:54
transferred so here we'll first of all
1:56
pass object one and then from which
1:59
object you want to transfer properties
2:01
so from this obj2 you need to transfer
2:04
these two properties into
2:08
the so we simply write
2:15
obj2 so it basically does the copy
2:19
operation so the both these properties
2:23
will be transferred into the first
2:25
object so if you console log this now
2:28
you will see two properties right here
2:33
but now after this operation let me
2:36
console log the same object obj1 once
2:39
again now you will see after this
2:42
operation after this method call which
2:44
is object. assign now you will see a
2:46
slight difference first of all we have
2:48
two properties name and age now we have
2:52
name Age Country and runs so now we have
2:55
four properties so after this operation
2:58
both these properties were transferred
2:59
to the parent object it was copied
3:03
successfully you can see this country
3:05
and runs object these properties were
3:07
transferred to the parent object this
3:10
object was not modified this obj2 obj1
3:13
was
3:14
modified all these properties were
3:17
merged into a single object were copied
3:20
using this object. assign method so we
3:23
basically passed the first object in
3:24
which the properties need to be
3:26
transferred and then the obj2 this is a
3:29
second object object so
3:31
here the properties these properties
3:33
will be transferred to this object and
3:36
then this object is
3:38
changed so we see this output if you
3:41
console log the obj2 it Remains the Same
3:45
it doesn't get changed at all so it
3:47
again contains these two properties so
3:49
it doesn't get changed so now we can
3:52
even declare
3:54
obj3 so we can have some more additional
3:57
properties so we can simply say here
4:01
some other property let's
4:06
suppose
4:11
average and
4:14
marks so let's suppose we want to also
4:17
transfer these property as well so again
4:20
you'll simply say
4:24
obj3 so what you will see now you will
4:27
also now see these three these two
4:30
properties added which is average and
4:32
Max to this
4:34
obj1 so both the properties which were
4:37
available in this obj 2 obj3 has been
4:40
successfully copied and merged and if
4:42
you see the output we have already we
4:45
have name AG country and runs average
4:49
you'll see all these things
4:52
are transferred into the single object
4:56
which was obj1 so in this way guys you
4:58
can use this method which is object.
5:00
assign to if you want to actually copy
5:02
the properties of one object into
5:05
another and you can pass multiple
5:07
objects right here if you want to
5:09
transfer the
5:11
properties so in this way you can use
5:14
this method it's really used in many
5:16
applications I have personally used this
5:18
method a lot of times in applications if
5:20
you want to transfer properties from one
5:22
object to another so thank you very much
5:24
for watching this video please hit that
5:26
like button subscribe the channel and do
5:28
check out my website free mediat
5:30
tools.com which contains audio video and
5:34
image tools open source website so I
5:38
will be seeing you in the next video
#Programming
#Scripting Languages
