TypedArray ऑब्जेक्ट का copyWithin() फंक्शन इस TypedArray की सामग्री को इसके भीतर ही कॉपी करता है। यह मेथड तीन नंबर स्वीकार करता है जहां पहला नंबर सरणी के इंडेक्स को दर्शाता है जिस पर एलिमेंट्स की कॉपी शुरू होनी चाहिए और, अगले दो नंबर सरणी के प्रारंभ और अंत एलिमेंट्स को दर्शाते हैं जिनसे डेटा कॉपी किया जाना चाहिए (लिया जाना चाहिए)।
सिंटैक्स
इसका सिंटैक्स निम्नानुसार है:
typedArray.copyWithin(target, start[, end])
उदाहरण
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55 ]); document.write("Contents of the typed array: "+int32View); int32View.copyWithin(5, 0, 5); document.write("<br>"); document.write("Contents of the typed array after copy: "+int32View); </script> </body> </html>
आउटपुट
Contents of the typed array: 21,64,89,65,33,66,87,55 Contents of the typed array after copy: 21,64,89,65,33,21,64,89
उदाहरण
इस फंक्शन को तीसरा पैरामीटर पास करना अनिवार्य नहीं है (सरणी के अंत एलिमेंट्स जिनसे डेटा कॉपी किया जाना चाहिए) यह सरणी के अंत तक कॉपी करेगा।
<html> <head> <title>JavaScript Example</title> </head> <body> <script type="text/javascript"> var int32View = new Int32Array([21, 64, 89, 65, 33, 66, 87, 55 ]); document.write("Contents of the typed array: "+int32View); int32View.copyWithin(5, 0); document.write("<br>"); document.write("Contents of the typed array after copy: "+int32View); </script> </body> </html>
आउटपुट
Contents of the typed array: 21,64,89,65,33,66,87,55 Contents of the typed array after copy: 21,64,89,65,33,21,64,89