Adds one or more elements in the beginning of the given array
unshift() function இங்கு ஒரு array இன் ஆரம்பத்தில் ஒன்று அல்லது அதற்கு மேற்பட்ட element களை add செய்வதற்கு பயன்படுகிறது
unshift() Function in Javascript
unshift() function இங்கு ஒரு array இன் ஆரம்பத்தில் ஒன்று அல்லது அதற்கு மேற்பட்ட element களை add செய்வதற்கு பயன்படுகிறது.
array.unshift(element1,element2,....,elementn)
Example1
<script>
var data = ["peacock","parrot","cat"];
data.unshift("hen");
document.writeln(data);
</script>
மேலே உள்ள Example1-ஐ கவனிக்கவும் இங்கு data என்ற variable இல் ["peacock","parrot","cat"] என்ற array values ஆனது store செய்யபட்டுள்ளது.இங்கு data.unshift("hen") என்ற function பயன்படுத்தபடுகிறது, இந்த function "hen" என்ற string ஐ data என்ற array இன் ஆரம்பத்தில் add செய்கிறது எனவே output ["hen","peacock","parrot","cat"] கிடைக்கிறது.output ஐ கவனிக்கவும்.
["hen","peacock","parrot","cat"]
Example2
<script>
var input = ["Leopard","Cheetah","Bear"];
input.unshift("Elephant","Crocodile");
document.writeln(input);
</script>
மேலே உள்ள Example2-ஐ கவனிக்கவும் இங்கு input என்ற variable இல் ["Leopard","Cheetah","Bear"] என்ற array values ஆனது store செய்யபட்டுள்ளது. இங்கு input.unshift("Elephant","Crocodile") என்ற function பயன்படுத்தபடுகிறது, இந்த function "Elephant","Crocodile" என்ற string ஐ input என்ற array இன் ஆரம்பத்தில் add செய்கிறது எனவே output ["Elephant","Crocodile","Leopard","Cheetah","Bear"] கிடைக்கிறது. output ஐ கவனிக்கவும்.
["Elephant","Crocodile","Leopard","Cheetah","Bear"]