愚者樹屋

|
Home About Contact
|

series

3d軟體 (1) apache (1) css (4) eagle (1) godot (8) google-api (1) google翻譯 (1) html (6) hugo安裝 (7) javasciprt (1) javascript (14) jquery (3) mysql (9) notepad++ (1) php (33) python (1) unity (1) yt-dlp (1) 像素畫 (1) 免費軟體 (8) 壓力測試 (2) 弱點掃描修補 (1) 無障礙網站 (1) 社群網站 (1) 遊戲推薦 (5) 雜記 (1)

Tags

2d軟體 3d軟體 ai apache css eagle godot google-api google翻譯 html hugo javasciprt javascript jquery mysql notepad++ php python tcpdf unity

javascript 物件轉陣列

post date - 2023/12/09
last update - 2023/12/09

使用ajax時陣列資料傳送到前端時會呈現物件的狀態,這邊記錄一下將他轉換成array來使用的方式。

方法

下方紀錄兩種寫法都可以轉換

//物件資料
var obj = {"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
//方法1
var result = Object.keys(obj).map((key) => [key, obj[key]]);
//方法2
var result = Object.entries(obj);

參考資料

https://stackoverflow.com/questions/38824349/how-to-convert-an-object-to-an-array-of-key-value-pairs-in-javascript

Tags : javascript

series

3d軟體 (1) apache (1) css (4) eagle (1) godot (8) google-api (1) google翻譯 (1) html (6) hugo安裝 (7) javasciprt (1) javascript (14) jquery (3) mysql (9) notepad++ (1) php (33) python (1) unity (1) yt-dlp (1) 像素畫 (1) 免費軟體 (8) 壓力測試 (2) 弱點掃描修補 (1) 無障礙網站 (1) 社群網站 (1) 遊戲推薦 (5) 雜記 (1)

Tags

2d軟體 3d軟體 ai apache css eagle godot google-api google翻譯 html hugo javasciprt javascript jquery mysql notepad++ php python tcpdf unity

Recent Posts

php取得使用者ip

2022/09/17

php 字串處理

2022/11/25

javascript字串型別轉換

2022/11/13

php呼叫父項函數

2023/09/29

php顯示404

2023/04/01

mastodon misskey pixiv plurk twitter 巴哈姆特

© 2022-2026 愚者樹屋