js筆記

常用軟體,程式語言的筆記和疑問
Forum rules
盡量做到:
每一個貼子都精心編輯;
每一個疑問都得到解答。
ejsoon
Site Admin
Posts: 3606
Joined: 2016 Jan 10, 22:15

js object to array

Post by ejsoon » 2018 Jun 11, 14:32

Object.keys(obj).map(function (key) { return obj[key]; });

from here.

ejsoon
Site Admin
Posts: 3606
Joined: 2016 Jan 10, 22:15

js圖片上傳轉base64

Post by ejsoon » 2018 Jul 13, 17:23

鏈接在。主要代碼:

Code: Select all

function getBase64(file) {
   var reader = new FileReader();
   reader.readAsDataURL(file);
   reader.onload = function () {
     console.log(reader.result);
   };
   reader.onerror = function (error) {
     console.log('Error: ', error);
   };
}

var file = document.querySelector('#files > input[type="file"]').files[0];
getBase64(file); // prints the base64 string

Post Reply