JS format JSON

如何用 Javascript format JSON 解決方法: 我們可以使用JSON.stringify 來 format e.g. var c = {a : "test", b:{ data: "asdada"}} JSON.stringify(c, null, 4) "{ "a": "test", "b": { "data": "asdada" } }" Hope you find it useful

Useful Heroku command

最近又多用了 Heroku 無左 Microsoft Azure 既 subscription 又怕佢 charge 貴 用 free tier 時發現好似好多野都要收錢咁 剛剛 deploy 了一個 NodeJS project 時 Load 唔起.. 又唔知可以點睇 log. 由於同一隻 App 都是放在 githu 月 Login heroku login List Application heroku apps Show log heroku logs --tail -a AppName Hope you find it useful

Firebase ReactJs routing issue - Page not found

使用 firebase hosting 來 host reactjs 既時候 出現了以下問題 當我直接在 browser 輸入 ReactJs 的 route 既時候 出現了 Page Not Found This file does not exist and there was no index.html found in the current directory or 404.html in the root directory 解決方法: 我們只需要在 firebase.json 的 hosting section 加上 rewrites 到 index.html 便可以了 { "hosting": { "public": "build", "ignore": [ "firebase.json", "**/.*", "**/node_modules/**" ], "rewrites": [ { "source": "**", "destination": "/index.html" } ] } } Hope you find it useful

How to get distinct values from an array of objects in JavaScript

今日有個 task 其中一個地方要在 Array of Json object 中 Distinct 一個 property const data = [ { id: 1, category: 'fruit', name: 'Apple', }, { id: 2, category: 'fruit', name: 'Banana', }, { id: 3, category: 'herb', name: 'Basil', }, { id: 4, category: 'herb', name: 'Rosemary', }, { id: 5, category: 'fruit', name: 'Dragon Fruit', }, ]; 解決方法: (ES5) var categories = // try to retrieve specific property function(item) { return item.