javascript firestore object sort

const bookListsQuery = await modules.firestore.collection('books') .get(); const sortedObj = Object.values(bookListsQuery.docs).sort(function(a, b){ console.log('a %s b %s', a.data().order, b.data().order) return Number(a.data().order) > Number(b.data().order); }); sortedObj.forEach(function(doc){ console.log(doc.data()) }); other way object use map to array, then it sorted. const bookListsQuery = await modules.firestore.collection('books') .get(); const sortedArr = bookListsQuery.docs.map(function (doc) { // 轉換成array return doc.data() }); sortedArr.sort(function compare(a, b) { return a.order > b.order; // 升 小->大 }); sortedArr.forEach(function(data){ console.log(data.data()) }) ========== Sorting multiple object properties with JavaScript https://bithacker.dev/javascript-object-multi-property-sort ...

2020-03-19 · 1 min · 163 words · Me

javascript console.log object

console.log(‘show value string, object %s %O’, var.string, var.object);

2019-08-07 · 1 min · 8 words · Me

async await Promise.all

async getaaa() async getbbb() async getccc() =======new way======= async refreshall(){ await Promise.all( xxxxxx.map(async (value, index) =>{ aaa = await getaaa() })) await Promise.all( xxxxxx.map(async (value, index) =>{ bbb = await getbbb() })) await Promise.all( xxxxxx.map(async (value, index) =>{ ccc = await getccc() })) } =======old way======= async refreshall(){ await Promise.all( xxxxxx.map(async (value, index) =>{ aaa = await getaaa() bbb = await getbbb() ccc = await getccc() })) } 1. map usually return something, here just throw 2. if use foreach(), get error. Like foreach is not function, can’t async await. ...

2018-05-24 · 1 min · 111 words · Me

call by value call by reference object array push

Problem: array A A.push(item) item is object from for or map or foreach….etc show A all add item is same……. Solve: var txxxxx = [] // xxxx is any word =====loop start===== txxxx[index] = item //index is from for or map or foreach…etc ot = { xxxx: txxxx[index] } A.push(ot) =====loop end=====

2018-05-23 · 1 min · 52 words · Me

[轉]async 、 await es6 promise javqscript

https://hackmd.io/s/Bko9gUGYZ

2017-08-29 · 1 min · word · Me