{"id":12486,"date":"2020-02-24T11:13:31","date_gmt":"2020-02-24T19:13:31","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12486"},"modified":"2023-12-01T02:30:14","modified_gmt":"2023-12-01T10:30:14","slug":"ruby-array-methods","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/","title":{"rendered":"Ruby Array Methods"},"content":{"rendered":"\n<p>Arrays are a data type that allows you to store lists of data in your code. Data in an array can be sorted, reversed, extracted, and amended. You can also search through an array to find a specific value, and convert data within an array to another type of data.<\/p>\n\n\n\n<p>In this guide, we are going to break down the most common Ruby array methods that you may want to use when you\u2019re writing code.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Retrieving Items<\/h2>\n\n\n\n<p>In Ruby, arrays can be used to store a list of data. Arrays can include strings, numbers, objects, or any other type of data. If you had a list of employee names, for example, you may want to declare an array to store those names, rather than store them in separate variables.<\/p>\n\n\n\n<p>Here is an example of how to create an array in Ruby:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]<\/pre><\/div>\n\n\n\n<p>Our array contains four names. However, when we call our array, we will be given all four of our names. So how do we get each one individually? Each of these names is given an index number, which we can use to access each value.<\/p>\n\n\n\n<p>The first value in an array has the index number <code>0<\/code>, and each item counts up from that value. Here are the index values for our above array:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>Hannah<\/td><td>John<\/td><td>Jose<\/td><td>Kaitlin<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>So, if we wanted to get the second array object, we could use the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print employees[1]<\/pre><\/div>\n\n\n\n<p>This would return <code>John<\/code>, whose name has the position index value of <code>1<\/code>.<\/p>\n\n\n\n<p>That is the basics of accessing elements from an array.<\/p>\n\n\n\n<p>In addition, we can also retrieve multiple items from our array instead of a single element. In order to do so, we need to specify a range of elements that we want to get, using their index values. For example, if we want to get the elements with an index value between 1 and 3, we could use this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>print employees[1,3]<\/pre><\/div>\n\n\n\n<p>Our code creates a new array with these elements, and returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"John\", \"Jose\", \"Kaitlin\"]<\/pre><\/div>\n\n\n\n<p>The <code>slice()<\/code> function also performs a similar task. If you want to get the values with index numbers between 1 and 3, you could use this code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees.slice(1,3)<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Sorting an Array<\/h2>\n\n\n\n<p>Sorting data is a common operation in any programming language. For example, you may have a list of names that you would like sorted in alphabetical or reverse alphabetical order. Let\u2019s break down how we can sort values in Ruby.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Reverse<\/h3>\n\n\n\n<p>The <code>reverse<\/code> method allows us to reverse the order of the elements contained within an array. This can be useful if you already have an organized list of data that you want to be flipped into reverse order. Here is an example of the <code>reverse<\/code> method being used:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]\nreversed = employees.reverse\nprint reversed<\/pre><\/div>\n\n\n\n<p>Our code returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"Kaitlin\", \"Jose\", \"John\", \"Hannah\"]<\/pre><\/div>\n\n\n\n<p>This function is useful if your array is already sorted, but what if your array is not sorted? That\u2019s where the Ruby <code>sort<\/code> method comes in.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Sort<\/h3>\n\n\n\n<p>Ruby\u2019s <code>sort<\/code> method allows you to sort data based on your needs. If we use the sort method without any parameters, we can sort a list in alphabetical order like so:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"Jose\", \"John\", \"Kaitlin\"]\nsorted = employees.sort\nprint sorted<\/pre><\/div>\n\n\n\n<p>Our program returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]<\/pre><\/div>\n\n\n\n<p>You can also specify your own sort algorithm if you have a specific sort in mind. Let\u2019s say you want to sort your list in reverse order. You could use the following sort: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"Jose\", \"John\", \"Kaitlin\"]\nsorted = employees.sort{|a,b| b &lt;=&gt; a}\nprint sorted<\/pre><\/div>\n\n\n\n<p>Here is the result of our code: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"Kaitlin\", \"Jose\", \"John\", \"Hannah\"]<\/pre><\/div>\n\n\n\n<p>As you can see, our code has reversed our list. There is a lot going on here, so let\u2019s break it down.&nbsp;<\/p>\n\n\n\n<p>The sort function performs a comparison between the objects in our array. The <code>&lt;=&gt;<\/code> operator\u2014also known as the spaceship operator\u2014compares two objects and returns -1 if the object on the left is smaller, 0 if the objects are identical, and 1 if the object on the left is bigger. In the process, our code arranges our values based on the result of the operator.<\/p>\n\n\n\n<p>It\u2019s worth noting that our original array remains the same\u2014sort did not modify the array\u2014and our sorted array is stored in its own variable.&nbsp;<\/p>\n\n\n\n<p>If we wanted to sort a list in ascending order, we would change our comparison like so:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"Jose\", \"John\", \"Kaitlin\"]\nsorted = employees.sort{|a,b| a &lt;=&gt; b}\nprint sorted<\/pre><\/div>\n\n\n\n<p>Our code returns the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Finding Array Items<\/h2>\n\n\n\n<p>There are a few Ruby functions that can be used to find array items: include, find, and select and reject.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Include<\/h3>\n\n\n\n<p>In our code above, we were able to retrieve items by their index value. But what if we want to look for a specific item in our array? That\u2019s where the <code>include?<\/code> method comes in.<\/p>\n\n\n\n<p>By using the <code>include?<\/code> method, we are able to search through our array and find out whether it contains a particular value. Here is an example of the <code>include?<\/code> method in action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]\nemployees.include? \"Kaitlin\"<\/pre><\/div>\n\n\n\n<p>Our code returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>true<\/pre><\/div>\n\n\n\n<p>It\u2019s worth noting that you can only use include to find whether an array includes an exact item. You cannot specify partial terms when you\u2019re working with the <code>include?<\/code> function. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Find<\/h3>\n\n\n\n<p>If you are looking to locate an element within an array, you can use the <code>find?<\/code> function. The <code>find?<\/code> method locates and returns the first element in an array that matches a certain condition that you specify. For example, let\u2019s say you are looking to find the employee name that includes <code>Jos<\/code>. Here is the code you would use:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]\nresult = employees.find {|i| i.include?(\"Jos\")}\nprint result<\/pre><\/div>\n\n\n\n<p>Here is what our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Jose<\/pre><\/div>\n\n\n\n<p>Our program searched through the array to find any values that included <code>Jos<\/code>, then returned the first one that matched our condition. The <code>find?<\/code> function stops as soon as it finds the value we are searching for. And if a program does not find any values, it would return <code>nil<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Select and Reject<\/h3>\n\n\n\n<p>The <code>select?<\/code> function can be used to find an item in an array as well. The main difference between <code>select?<\/code> and <code>find?<\/code> is that the <code>select?<\/code> method returns a new array with the values that meet our criteria, whereas <code>find?<\/code> only returns the first value that meets our criteria.<\/p>\n\n\n\n<p>Here\u2019s an example of the select method in action: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]\nresult = employees.select {|i| i.include?(\"Jo\")}\nprint result<\/pre><\/div>\n\n\n\n<p>Our code returns the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"John\", \"Jose\"]<\/pre><\/div>\n\n\n\n<p>Two values in our array\u2014John and Jose\u2014included <code>Jo<\/code>, and so our program returned both of them.<\/p>\n\n\n\n<p>Similarly, if we wanted to retrieve the values in an array that do not match our conditions, we can use the <code>reject?<\/code> function. The <code>reject?<\/code> method works in the same way as <code>select?<\/code>, but returns all the values that do not meet our criteria. Here\u2019s an example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]\nresult = employees.reject {|i| i.include?(\"o\")}\nprint result<\/pre><\/div>\n\n\n\n<p>Our code returns all of the names that do not include the letter <code>o<\/code>, which are as follows: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"Hannah\", \"Kaitlin\"]<\/pre><\/div>\n\n\n\n<p>Both select and reject return a new array and do not change the previous array.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Removing Duplicate Values<\/h2>\n\n\n\n<p>Often, when you\u2019re working with a list, the list will contain duplicate values. This can be a problem because the more values your list has, the longer it will take your program to iterate through the list.<\/p>\n\n\n\n<p>The <code>uniq<\/code> array method can be used to remove duplicate elements from an array. Here\u2019s an example:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"Alex\", \"Paul\", \"Katie\", \"Linda\", \"Alex\"].uniq<\/pre><\/div>\n\n\n\n<p>Our code returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[\"Alex\", \"Paul\", \"Katie\", \"Linda\"]<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Reducing Arrays<\/h2>\n\n\n\n<p>When you\u2019re working with an array, there may be a specific piece of information that you want to retrieve about the array. For example, you may want to get the total of values within an array. We can use the <code>reduce<\/code> function to accomplish this goal.<\/p>\n\n\n\n<p>Reduce iterates through an array and keeps a running total of the values we have added. The reduce function takes in one parameter: the starting value of the operation (this is <code>0<\/code> by default).<\/p>\n\n\n\n<p>Here\u2019s an example of the reduce function in action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>get_combined_age = [8, 16, 19].reduce(0) { | total, current | total += current }\nprint get_combined_age<\/pre><\/div>\n\n\n\n<p>Our code produces the following result: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>43<\/pre><\/div>\n\n\n\n<p>As you can see, the reduce function has added up the total value of every item in our array.<\/p>\n\n\n\n<p>You can also use reduce to transform values within an array or perform another operation on those values. Here\u2019s an example of a reduce function that will add one to each item in our array:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>values = [1, 3, 5, 7, 9]\nnew_values = values.reduce([]) do | array, cur |\n\tvalue = cur + 1\n\tarray.push(value)\nend\nprint new_values<\/pre><\/div>\n\n\n\n<p>Our code adds one to each item within our array, and returns a new array:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[2, 4, 6, 8, 10]<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Transforming Values<\/h2>\n\n\n\n<p>Let\u2019s say you want to perform an operation on each element of your array. Perhaps you have a list of ages and you want to know how old everyone will be in five years. We can use the Ruby <code>map<\/code> method to transform the contents of our array.<\/p>\n\n\n\n<p>Here is an example of the map function in action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>ages = [8, 9, 12, 14, 18]\nin_five_years = ages.map{|i| i + 5}\nprint in_five_years<\/pre><\/div>\n\n\n\n<p>Our code returns the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>[13, 14, 17, 19, 23]<\/pre><\/div>\n\n\n\n<p>As you can see, our program has added five to each value in our array. While this may not be the most useful implementation of <code>map<\/code>, there are many occasions where the function could be useful. For example, if you wanted to loop through a list of names and change them based on certain criteria, you could do so using the <code>map<\/code> method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Converting an Array to String<\/h2>\n\n\n\n<p>When you\u2019re working with arrays, there may be a situation where you want an array to appear as a string. For example, if you have a list of property names for sale, you may want a user to see the list, rather than an array of items.<\/p>\n\n\n\n<p>That\u2019s where the <code>join<\/code> method comes in. Join converts an array into a string, and gives you control over how the elements are combined. The <code>join<\/code> method takes one argument: the character(s) that you want to use to separate the items within an array.<\/p>\n\n\n\n<p>Here is an example of Ruby join in action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]\nresult = employees.join(\", \")\nprint result<\/pre><\/div>\n\n\n\n<p>Our code returns the following: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>Hannah, John, Jose, Kaitlin<\/pre><\/div>\n\n\n\n<p>As you can see, our program has converted our array into a string and separated each value with a comma and a space. If we were to specify no separator, our array would still be converted into a string, but there would be no spaces: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>employees = [\"Hannah\", \"John\", \"Jose\", \"Kaitlin\"]\nresult = employees.join\nprint result<\/pre><\/div>\n\n\n\n<p>Here is what our code returns:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>HannahJohnJoseKaitlin<\/pre><\/div>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>In this guide, we have broken down many of the most common Ruby array methods. We have explored how to retrieve information from an array, how to sort an array, how to transform data within an array, and more. These functions all have a wide variety of applications in Ruby.<\/p>\n\n\n\n<p>Now you\u2019re an expert at working with arrays in Ruby!<\/p>\n","protected":false},"excerpt":{"rendered":"Arrays are a data type that allows you to store lists of data in your code. Data in an array can be sorted, reversed, extracted, and amended. You can also search through an array to find a specific value, and convert data within an array to another type of data. In this guide, we are&hellip;","protected":false},"author":240,"featured_media":12487,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17278],"tags":[],"class_list":{"0":"post-12486","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ruby"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"Ruby","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Ruby Array Methods: A Complete Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"Ruby contains a number of array methods that can be used to manipulate arrays. Learn about how to work with Ruby arrays in this article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Ruby Array Methods\" \/>\n<meta property=\"og:description\" content=\"Ruby contains a number of array methods that can be used to manipulate arrays. Learn about how to work with Ruby arrays in this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-02-24T19:13:31+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:30:14+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"667\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"Ruby Array Methods\",\"datePublished\":\"2020-02-24T19:13:31+00:00\",\"dateModified\":\"2023-12-01T10:30:14+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/\"},\"wordCount\":1662,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg\",\"articleSection\":[\"Ruby\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/\",\"name\":\"Ruby Array Methods: A Complete Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg\",\"datePublished\":\"2020-02-24T19:13:31+00:00\",\"dateModified\":\"2023-12-01T10:30:14+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"Ruby contains a number of array methods that can be used to manipulate arrays. Learn about how to work with Ruby arrays in this article.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg\",\"width\":1000,\"height\":667},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Ruby\",\"item\":\"https:\/\/careerkarma.com\/blog\/ruby\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Ruby Array Methods\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Ruby Array Methods: A Complete Guide | Career Karma","description":"Ruby contains a number of array methods that can be used to manipulate arrays. Learn about how to work with Ruby arrays in this article.","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:\/\/careerkarma.com\/blog\/ruby-array-methods\/","og_locale":"en_US","og_type":"article","og_title":"Ruby Array Methods","og_description":"Ruby contains a number of array methods that can be used to manipulate arrays. Learn about how to work with Ruby arrays in this article.","og_url":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-02-24T19:13:31+00:00","article_modified_time":"2023-12-01T10:30:14+00:00","og_image":[{"width":1000,"height":667,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"Ruby Array Methods","datePublished":"2020-02-24T19:13:31+00:00","dateModified":"2023-12-01T10:30:14+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/"},"wordCount":1662,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg","articleSection":["Ruby"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/","url":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/","name":"Ruby Array Methods: A Complete Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg","datePublished":"2020-02-24T19:13:31+00:00","dateModified":"2023-12-01T10:30:14+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"Ruby contains a number of array methods that can be used to manipulate arrays. Learn about how to work with Ruby arrays in this article.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/ruby-array-methods\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/RUBY-ARRAY.jpg","width":1000,"height":667},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/ruby-array-methods\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Ruby","item":"https:\/\/careerkarma.com\/blog\/ruby\/"},{"@type":"ListItem","position":3,"name":"Ruby Array Methods"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12486","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12486"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12486\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12487"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12486"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12486"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12486"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}