If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
JavaScript Array unshift() method का use एक या एक से अधिक values को Array में prepend (insert) करने के लिए किया जाता है। Prepend होने वाली values Array के starting में insert होती हैं।
array.unshift(item1, item2, ..., itemN);
array | required : Input Array जिसमे new element prepend करना चाहते हैं।
item1, item2, ..., itemN | required : item , input value है जिसे Array में prepend करना है। input value किसी भी type की हो सकती है। आप कितनी ही values pass कर सकते हैं insert करने के लिए , लेकिन कम से कम एक तो होनी ही चाहिए।
Return Value : element insert होने के बाद Array Length return करता है।
Note : अगर empty Array के साथ unshift() method को call किया तो length 0 return होगी।
File : js_array_unshift.html
<!DOCTYPE html>
<html>
<body>
<script>
var arr = ["jQuery", "JavaScript"];
document.writeln("Total Elements : " +arr.unshift("PHP", "Laravel") + "<br>");
document.writeln("New Elements : " + arr);
</script>
</body>
</html>
Total Elements : 4 New Elements : PHP,Laravel,jQuery,JavaScript
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook