{"id":136,"date":"2026-05-05T10:12:49","date_gmt":"2026-05-05T10:12:49","guid":{"rendered":"https:\/\/gigz.pk\/javascript\/?post_type=lesson&#038;p=136"},"modified":"2026-05-05T10:12:51","modified_gmt":"2026-05-05T10:12:51","slug":"spread-operator","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator","title":{"rendered":"Spread Operator"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Introduction<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Spread Operator in JavaScript is a modern feature that allows you to expand or unpack elements from arrays, objects, or iterable data. It is represented by three dots and helps write cleaner and more efficient code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">What is the Spread Operator<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Spread Operator is used to copy, combine, or expand elements in arrays and objects. It simplifies tasks that would otherwise require loops or complex methods.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Syntax<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Spread Operator uses three dots followed by a variable name<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let newArray = &#91;...oldArray];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Core Purpose<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Spread Operator helps developers to<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Copy arrays and objects easily<br>Merge multiple arrays or objects<br>Pass multiple values into functions<br>Expand elements for flexible coding<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Using Spread Operator with Arrays<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You can copy or merge arrays using the Spread Operator<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let arr1 = &#91;1, 2, 3];<br>let arr2 = &#91;...arr1];<br>let combined = &#91;...arr1, 4, 5];<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using Spread Operator with Objects<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Spread Operator can also copy or merge objects<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>let user = { name: \"Ali\", age: 20 };<br>let updatedUser = { ...user, city: \"Lahore\" };<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Using Spread Operator in Functions<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">It allows passing array elements as individual arguments<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function sum(a, b, c) {<br>  return a + b + c;<br>}<br><br>let numbers = &#91;1, 2, 3];<br>sum(...numbers);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Key Features<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Simple and clean syntax<br>Reduces code complexity<br>Improves readability<br>Works with arrays and objects<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Advantages<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Saves time in copying and merging data<br>Avoids manual loops<br>Makes code more modern and efficient<br>Easy to learn and use<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Conclusion<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The Spread Operator is a powerful and essential feature in JavaScript. It simplifies data handling and improves code quality, making it a must learn concept for developers.<\/p>\n\n\n<div class=\"yoast-breadcrumbs\"><span><span><a href=\"https:\/\/gigz.pk\/javascript\">Home<\/a><\/span> \u00bb <span class=\"breadcrumb_last\" aria-current=\"page\">Advanced JavaScript > ES6+ Features > Spread Operator<\/span><\/span><\/div>\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777975948241\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1777975947896\"><strong class=\"schema-faq-question\"><\/strong> <p class=\"schema-faq-answer\"><\/p> <\/div> <\/div>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-136","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Spread Operator - Learn JavaScript with GIGZ.PK<\/title>\n<meta name=\"description\" content=\"Learn JavaScript spread operator to copy merge arrays and objects easily and write cleaner efficient code in modern web development\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spread Operator - Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"og:description\" content=\"Learn JavaScript spread operator to copy merge arrays and objects easily and write cleaner efficient code in modern web development\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator\" \/>\n<meta property=\"og:site_name\" content=\"Learn JavaScript with GIGZ.PK\" \/>\n<meta property=\"article:modified_time\" content=\"2026-05-05T10:12:51+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=spread-operator\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=spread-operator\",\"name\":\"Spread Operator - Learn JavaScript with GIGZ.PK\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\"},\"datePublished\":\"2026-05-05T10:12:49+00:00\",\"dateModified\":\"2026-05-05T10:12:51+00:00\",\"description\":\"Learn JavaScript spread operator to copy merge arrays and objects easily and write cleaner efficient code in modern web development\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=spread-operator#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=spread-operator\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?lesson=spread-operator#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/javascript\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Advanced JavaScript > ES6+ Features > Spread Operator\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/\",\"name\":\"Learn JavaScript with GIGZ.PK\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/javascript\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spread Operator - Learn JavaScript with GIGZ.PK","description":"Learn JavaScript spread operator to copy merge arrays and objects easily and write cleaner efficient code in modern web development","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator","og_locale":"en_US","og_type":"article","og_title":"Spread Operator - Learn JavaScript with GIGZ.PK","og_description":"Learn JavaScript spread operator to copy merge arrays and objects easily and write cleaner efficient code in modern web development","og_url":"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator","og_site_name":"Learn JavaScript with GIGZ.PK","article_modified_time":"2026-05-05T10:12:51+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":["WebPage","FAQPage"],"@id":"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator","url":"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator","name":"Spread Operator - Learn JavaScript with GIGZ.PK","isPartOf":{"@id":"https:\/\/gigz.pk\/javascript\/#website"},"datePublished":"2026-05-05T10:12:49+00:00","dateModified":"2026-05-05T10:12:51+00:00","description":"Learn JavaScript spread operator to copy merge arrays and objects easily and write cleaner efficient code in modern web development","breadcrumb":{"@id":"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/javascript\/?lesson=spread-operator"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/javascript\/?lesson=spread-operator#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/javascript"},{"@type":"ListItem","position":2,"name":"Advanced JavaScript > ES6+ Features > Spread Operator"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/javascript\/#website","url":"https:\/\/gigz.pk\/javascript\/","name":"Learn JavaScript with GIGZ.PK","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/javascript\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/javascript\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}