{"id":846,"date":"2023-04-24T05:00:00","date_gmt":"2023-04-24T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=846"},"modified":"2023-04-21T14:36:58","modified_gmt":"2023-04-21T21:36:58","slug":"keyvalue-pipe","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/keyvalue-pipe\/","title":{"rendered":"keyValue pipe"},"content":{"rendered":"\n<p>The <code><a href=\"https:\/\/angular.io\/api\/common\/KeyValuePipe\" target=\"_blank\" rel=\"noopener\" title=\"\">keyValue<\/a><\/code> pipe turns any object into an array of key-value pairs, which can be helpful for debugging purposes or working with an object with a dynamic shape.<\/p>\n\n\n\n<p>Here&#8217;s an example:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"504\" height=\"93\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/04\/image-38.png\" alt=\"\" class=\"wp-image-848\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/04\/image-38.png 504w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/04\/image-38-300x55.png 300w\" sizes=\"auto, (max-width: 504px) 100vw, 504px\" \/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>In this example, we&#8217;re using the <code>keyValue<\/code> pipe to iterate over the properties of <code>user<\/code> and display them. The <code>item<\/code> variable represents each key-value pair in the object, and we&#8217;re using the <code>item.key<\/code> and <code>item.value<\/code> properties to display the key and value for each item.<\/p>\n\n\n\n<p>As a result, if <code>user<\/code> is this object:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"300\" height=\"150\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/04\/image-39.png\" alt=\"\" class=\"wp-image-849\"\/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>The component displays:<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"164\" height=\"94\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/04\/image-40.png\" alt=\"\" class=\"wp-image-850\"\/><\/figure>\n<\/div>\n\n\n<p><\/p>\n\n\n\n<p>You can see the above <a href=\"https:\/\/stackblitz.com\/edit\/at-keyvalue-pipe?file=src%2Fmain.ts,src%2Fmain.html\" target=\"_blank\" rel=\"noopener\" title=\"\">example in action on Stackblitz<\/a>.<\/p>\n\n\n\n<p>This pipe is part of my <a href=\"https:\/\/blog.angulartraining.com\/3-angular-pipes-you-should-now-about-f635d6ab891f\" target=\"_blank\" rel=\"noopener\" title=\"\">collection of 3 Angular pipes everyone should know about<\/a>, including the <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/async-pipe-syntax-tricks\/\" target=\"_blank\" rel=\"noopener\" title=\"\"><code>async<\/code> pipe<\/a> and the <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/debugging-with-the-json-pipe\/\" target=\"_blank\" rel=\"noopener\" title=\"\"><code>json<\/code> pipe<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The keyValue pipe turns any object into an array of key-value pairs, which can be helpful for debugging purposes or working with an object with a dynamic shape. Here&#8217;s an example: In this example, we&#8217;re using the keyValue pipe to iterate over the properties of user and display them. The item variable represents each key-value [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,14],"tags":[],"class_list":["post-846","post","type-post","status-publish","format-standard","hentry","category-angular","category-pipes"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/846","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=846"}],"version-history":[{"count":3,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/846\/revisions"}],"predecessor-version":[{"id":852,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/846\/revisions\/852"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=846"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=846"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=846"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}