{"id":13,"date":"2014-05-27T22:37:50","date_gmt":"2014-05-27T22:37:50","guid":{"rendered":"http:\/\/localhost\/wordpress\/?p=13"},"modified":"2014-05-27T22:40:47","modified_gmt":"2014-05-27T22:40:47","slug":"cut-the-unwanted-tail","status":"publish","type":"post","link":"https:\/\/blog.silverterra.net\/?p=13","title":{"rendered":"cut the unwanted tail"},"content":{"rendered":"<p>There is a big array and the items joined by comma like this:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nvar arr = [...];\r\nvar joined = arr.join(',');\r\nconsole.log(joined);\r\n\r\n-&gt; a,w,e,,,,q,,t,z,,,,,,,,,,,\r\n\r\n<\/pre>\n<p>I don&#8217;t need the end with the many unwanted comma. I try to cut the string at the last real value.<br \/>\nLet&#8217;s extend the string object with the followings:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nif (!String.prototype.dropFromEnd) {\r\n  Object.defineProperty(String.prototype, 'dropFromEnd', {\r\n    enumerable: false,\r\n    configurable: false,\r\n    writable: false,\r\n    value: function (searchString) {\r\n      var regEx = new RegExp(searchString + '+$', 'g');\r\n      return this.replace(regEx,&quot;&quot;);\r\n    }\r\n  });\r\n};\r\n<\/pre>\n<p>to call this:<\/p>\n<pre data-enlighter-language=\"js\" class=\"EnlighterJSRAW\">\r\nvar joined = 'a,w,e,,,,q,,t,z,,,,,,,,,,,'.dropFromEnd(',');\r\nconsole.log(joined);\r\n\r\n-&gt; a,w,e,,,,q,,t,z\r\n\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>There is a big array and the items joined by comma like this: I don&#8217;t need the end with the many unwanted comma. I try to cut the string at the last real value. Let&#8217;s extend the string object with the followings: to call this:<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[],"class_list":["post-13","post","type-post","status-publish","format-standard","hentry","category-javascript"],"_links":{"self":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/13","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=13"}],"version-history":[{"count":1,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions"}],"predecessor-version":[{"id":14,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=\/wp\/v2\/posts\/13\/revisions\/14"}],"wp:attachment":[{"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=13"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=13"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.silverterra.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=13"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}