{"id":2615,"date":"2017-03-13T14:35:04","date_gmt":"2017-03-13T13:35:04","guid":{"rendered":"http:\/\/codingexplained.com\/?p=2615"},"modified":"2017-06-11T20:48:47","modified_gmt":"2017-06-11T18:48:47","slug":"looping-number-ranges","status":"publish","type":"post","link":"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges","title":{"rendered":"Looping through Number Ranges"},"content":{"rendered":"<p>\n<iframe width=\"560\" height=\"315\" src=\"https:\/\/www.youtube.com\/embed\/opfQMJQZN2Y\" frameborder=\"0\" allowfullscreen><\/iframe>\n<\/p>\n<p>In this short lecture, I am going to show you how you can output a range of numbers with the <span class=\"code\">v-for<\/span> directive. By specifying a number as the expression, the template will be repeated that number of times. So if I wanted to output a list of the numbers from one to ten, I would give the current number an alias followed by the in keyword and the number ten.<\/p>\n<pre><code class=\"html\">&lt;li v-for=&quot;n in 10&quot;&gt;&lt;\/li&gt;\r\n\r\n{{ n }}<\/code><\/pre>\n<p>What Vue.js does for us, is that it loops ten times and increments <span class=\"code\">n<\/span> by one for each iteration. And sure enough, we see a list containing the numbers from one to ten.<\/p>\n<p>This syntax also enables you to access the loop index in exactly the same way as you have previously seen.<\/p>\n<pre><code class=\"html\">&lt;li v-for=&quot;(n, index) in 10&quot;&gt;{{ n }}&lt;\/li&gt;<\/code><\/pre>\n<p>Now that we have the loop index available, we could do something like outputting <span class=\"code\">n<\/span> multiplied with <span class=\"code\">index<\/span>. I will output both numbers as well as the result of the multiplication.<\/p>\n<pre><code class=\"html\">{{ n }} * {{ index }} = {{ n * index }}<\/code><\/pre>\n<p>And as you can see, we now have access to both the range of numbers and the loop index, and we can do with those whatever we please.<\/p>\n<p>\n<script async src=\"\/\/jsfiddle.net\/Andy0708\/4wq6wo9n\/1\/embed\/js,html,result\/dark\/\"><\/script>\n<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"series\">Part 23 of 55 in the <a href=\"https:\/\/codingexplained.com\/tutorial\/vue-js-beginner-to-professional\" class=\"series-165\" title=\"Vue.js: From Beginner to Professional\">Vue.js: From Beginner to Professional<\/a> series<\/div><p>In this short lecture, I am going to show you how you can output a range of numbers with the v-for directive. By specifying a number as the expression, the template will be repeated that number of times. So if I wanted to output a list of the numbers from one to ten, I would&hellip; <a href=\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges\" class=\"more-link\">read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"Looping through Number Ranges","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false}}},"categories":[164],"tags":[168,166,167],"series":[165],"jetpack_publicize_connections":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.4 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Looping through Number Ranges in Vue.js<\/title>\n<meta name=\"description\" content=\"The v-for directive in Vue.js can also be used to loop through a range of numbers. See an example of looping through a range of numbers with v-for.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Looping through Number Ranges in Vue.js\" \/>\n<meta property=\"og:description\" content=\"The v-for directive in Vue.js can also be used to loop through a range of numbers. See an example of looping through a range of numbers with v-for.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges\" \/>\n<meta property=\"og:site_name\" content=\"Coding Explained\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/codingexplained\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/codingexplained\" \/>\n<meta property=\"article:published_time\" content=\"2017-03-13T13:35:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2017-06-11T18:48:47+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/codingexplained.com\/wp-content\/uploads\/2015\/11\/codingexplained-fb-promote.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"444\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Bo Andersen\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@codingexplained\" \/>\n<meta name=\"twitter:site\" content=\"@codingexplained\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Bo Andersen\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges\",\"url\":\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges\",\"name\":\"Looping through Number Ranges in Vue.js\",\"isPartOf\":{\"@id\":\"https:\/\/codingexplained.com\/#website\"},\"datePublished\":\"2017-03-13T13:35:04+00:00\",\"dateModified\":\"2017-06-11T18:48:47+00:00\",\"author\":{\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d\"},\"description\":\"The v-for directive in Vue.js can also be used to loop through a range of numbers. See an example of looping through a range of numbers with v-for.\",\"breadcrumb\":{\"@id\":\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/codingexplained.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Looping through Number Ranges\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/codingexplained.com\/#website\",\"url\":\"https:\/\/codingexplained.com\/\",\"name\":\"Coding Explained\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/codingexplained.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d\",\"name\":\"Bo Andersen\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/codingexplained.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g\",\"caption\":\"Bo Andersen\"},\"description\":\"I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!\",\"sameAs\":[\"https:\/\/codingexplained.com\",\"https:\/\/www.facebook.com\/codingexplained\",\"https:\/\/www.linkedin.com\/in\/ba0708\",\"https:\/\/twitter.com\/codingexplained\",\"https:\/\/www.youtube.com\/c\/codingexplained\"],\"url\":\"https:\/\/codingexplained.com\/author\/andy\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Looping through Number Ranges in Vue.js","description":"The v-for directive in Vue.js can also be used to loop through a range of numbers. See an example of looping through a range of numbers with v-for.","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:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges","og_locale":"en_US","og_type":"article","og_title":"Looping through Number Ranges in Vue.js","og_description":"The v-for directive in Vue.js can also be used to loop through a range of numbers. See an example of looping through a range of numbers with v-for.","og_url":"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges","og_site_name":"Coding Explained","article_publisher":"https:\/\/www.facebook.com\/codingexplained","article_author":"https:\/\/www.facebook.com\/codingexplained","article_published_time":"2017-03-13T13:35:04+00:00","article_modified_time":"2017-06-11T18:48:47+00:00","og_image":[{"width":1200,"height":444,"url":"https:\/\/codingexplained.com\/wp-content\/uploads\/2015\/11\/codingexplained-fb-promote.png","type":"image\/png"}],"author":"Bo Andersen","twitter_card":"summary_large_image","twitter_creator":"@codingexplained","twitter_site":"@codingexplained","twitter_misc":{"Written by":"Bo Andersen","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges","url":"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges","name":"Looping through Number Ranges in Vue.js","isPartOf":{"@id":"https:\/\/codingexplained.com\/#website"},"datePublished":"2017-03-13T13:35:04+00:00","dateModified":"2017-06-11T18:48:47+00:00","author":{"@id":"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d"},"description":"The v-for directive in Vue.js can also be used to loop through a range of numbers. See an example of looping through a range of numbers with v-for.","breadcrumb":{"@id":"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/codingexplained.com\/coding\/front-end\/vue-js\/looping-number-ranges#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/codingexplained.com\/"},{"@type":"ListItem","position":2,"name":"Looping through Number Ranges"}]},{"@type":"WebSite","@id":"https:\/\/codingexplained.com\/#website","url":"https:\/\/codingexplained.com\/","name":"Coding Explained","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/codingexplained.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/codingexplained.com\/#\/schema\/person\/e19c92ec991f571605f047cefeaa950d","name":"Bo Andersen","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/codingexplained.com\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/28f5826f9d5d544b0c5e1ec321dfdfb8?s=96&d=mm&r=g","caption":"Bo Andersen"},"description":"I am a back-end web developer with a passion for open source technologies. I have been a PHP developer for many years, and also have experience with Java and Spring Framework. I currently work full time as a lead developer. Apart from that, I also spend time on making online courses, so be sure to check those out!","sameAs":["https:\/\/codingexplained.com","https:\/\/www.facebook.com\/codingexplained","https:\/\/www.linkedin.com\/in\/ba0708","https:\/\/twitter.com\/codingexplained","https:\/\/www.youtube.com\/c\/codingexplained"],"url":"https:\/\/codingexplained.com\/author\/andy"}]}},"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p3mJkW-Gb","_links":{"self":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2615"}],"collection":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/comments?post=2615"}],"version-history":[{"count":2,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2615\/revisions"}],"predecessor-version":[{"id":2989,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/posts\/2615\/revisions\/2989"}],"wp:attachment":[{"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/media?parent=2615"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/categories?post=2615"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/tags?post=2615"},{"taxonomy":"series","embeddable":true,"href":"https:\/\/codingexplained.com\/wp-json\/wp\/v2\/series?post=2615"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}