{"id":4751,"date":"2024-06-09T15:48:14","date_gmt":"2024-06-09T10:18:14","guid":{"rendered":"https:\/\/namastedev.com\/blog\/?p=4751"},"modified":"2024-06-09T15:48:52","modified_gmt":"2024-06-09T10:18:52","slug":"solution-for-outputting-array-of-firstnames-less-than-age-of-30-only-using-reduce","status":"publish","type":"post","link":"https:\/\/namastedev.com\/blog\/solution-for-outputting-array-of-firstnames-less-than-age-of-30-only-using-reduce\/","title":{"rendered":"Solution for outputting array of firstnames less than age of 30, only using reduce"},"content":{"rendered":"<p>Hi, this is the solution for the homework question asked that is using only reduce to give the o\/p of the first names of the people whose age is. &lt; 30:<\/p>\n<pre class=\"ql-syntax\">const arr = [\n{ firstname: \"Akshay\", age: 26 },\n{ firstname: \"Donald\", age: 56 },\n{ firstname: \"deepika\", age: 26 },\n];\nconst op = arr.reduce(function (acc, curr) {\nif (curr.age &lt; 30) {\nacc.push(curr.firstname);\n}\nreturn acc;\n}, []); \n\/\/ we pass empty array as the inital value as accumulator and then push the \nfirstnames whose age &lt; 30\n\nconsole.log(op);<\/pre>\n<p>https:\/\/www.youtube.com\/watch?v=zdp0zrpKzIE -&gt; link to the video.<\/p>\n<p>Thanks,<br \/>\nAnush.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hi, this is the solution for the homework question asked that is using only reduce to give the o\/p of the first names of the people whose age is. &lt; 30: const arr = [ { firstname: &#8220;Akshay&#8221;, age: 26 }, { firstname: &#8220;Donald&#8221;, age: 56 }, { firstname: &#8220;deepika&#8221;, age: 26 }, ]; const<\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[333,334,172],"tags":[335,330],"class_list":["post-4751","post","type-post","status-publish","format-standard","category-asynchronous-javascript","category-best-practices","category-javascript","tag-best-practices","tag-javascript"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4751","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/comments?post=4751"}],"version-history":[{"count":2,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4751\/revisions"}],"predecessor-version":[{"id":4754,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/posts\/4751\/revisions\/4754"}],"wp:attachment":[{"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/media?parent=4751"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/categories?post=4751"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/namastedev.com\/blog\/wp-json\/wp\/v2\/tags?post=4751"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}