I am try to learn more about the JavaScript and I have one of the assignment where I have array and I need to duplicate that and return the result as below :
var smValue = [1,2,3];
smValue.duplicate() will give the output like :
[1,2,3,1,2,3]
I got stuck on that. I have tried to create function like that :
var smValue = [1,2,3];
fuction duplicate (){
for(i=0;i<=smValue.length;i++){
array[smValue.length + 1] = smValue.push(smValue[i]);
}
return array;
}
smValue.duplicate();
But failed. Please help me to resolve it. It may the vary basic but I have never seen this before.
array[4]key. In addition array wasn't declarated.Array.prototypeso you can't chain it to array itself